@overmap-ai/forms 1.0.0 → 1.0.2
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.
- package/dist/builder/utils.d.ts +1 -1
- package/dist/fields/BaseField/BaseField.d.ts +8 -0
- package/dist/fields/BooleanField/BooleanField.d.ts +17 -0
- package/dist/fields/DateField/DateField.d.ts +16 -0
- package/dist/fields/DateField/DateInput.d.ts +2 -2
- package/dist/fields/MultiStringField/MultiStringField.d.ts +30 -0
- package/dist/fields/NumberField/NumberField.d.ts +29 -0
- package/dist/fields/SelectField/BaseSelectField.d.ts +1 -0
- package/dist/fields/SelectField/MultiSelectField.d.ts +20 -0
- package/dist/fields/SelectField/SelectField.d.ts +19 -0
- package/dist/fields/StringOrTextFields/StringField/StringField.d.ts +19 -0
- package/dist/fields/StringOrTextFields/TextField/TextField.d.ts +16 -0
- package/dist/fields/UploadField/UploadField.d.ts +29 -0
- package/dist/fields/UploadField/UploadInput.d.ts +4 -0
- package/dist/fields/UploadField/index.d.ts +2 -0
- package/dist/fields/UploadField/utils.d.ts +1 -0
- package/dist/fields/constants.d.ts +2 -0
- package/dist/fields/utils.d.ts +2 -1
- package/dist/forms.js +980 -767
- package/dist/forms.umd.cjs +1 -1
- package/dist/style.css +1 -1
- package/dist/typings.d.ts +7 -1
- package/package.json +2 -2
package/dist/builder/utils.d.ts
CHANGED
|
@@ -8,4 +8,4 @@ export declare function insert<T>(list: T[] | undefined, index: number, value: T
|
|
|
8
8
|
export declare function remove<T>(list: T[], index: number): T[];
|
|
9
9
|
export declare const makeIdentifier: (existing: unknown, label: string) => string;
|
|
10
10
|
export declare const findFieldByIdentifier: (fields: ISerializedField[], identifier?: string) => ISerializedField | null;
|
|
11
|
-
export declare const makeConditionalSourceFields: (sections: SerializedFieldSection[], index: number) => (import("@overmap-ai/core").SerializedTextField | import("@overmap-ai/core").SerializedBooleanField | import("@overmap-ai/core").SerializedNumberField | import("@overmap-ai/core").SerializedDateField | import("@overmap-ai/core").SerializedStringField | import("@overmap-ai/core").SerializedSelectField | import("@overmap-ai/core").SerializedMultiStringField | import("@overmap-ai/core").SerializedMultiSelectField)[];
|
|
11
|
+
export declare const makeConditionalSourceFields: (sections: SerializedFieldSection[], index: number) => (import("@overmap-ai/core").SerializedTextField | import("@overmap-ai/core").SerializedBooleanField | import("@overmap-ai/core").SerializedNumberField | import("@overmap-ai/core").SerializedDateField | import("@overmap-ai/core").SerializedStringField | import("@overmap-ai/core").SerializedSelectField | import("@overmap-ai/core").SerializedMultiStringField | import("@overmap-ai/core").SerializedMultiSelectField | import("@overmap-ai/core").SerializedUploadField)[];
|
|
@@ -21,9 +21,17 @@ export declare abstract class BaseField<TValue extends FieldValue, TIdentifier e
|
|
|
21
21
|
private readonly formValidators;
|
|
22
22
|
private readonly fieldValidators;
|
|
23
23
|
readonly label: string;
|
|
24
|
+
/**
|
|
25
|
+
* By default, validation doesn't execute on `onChange` events when editing fields
|
|
26
|
+
* until the field has been `touched`. This can be overridden by setting this to `false`
|
|
27
|
+
* if you want to validate on every `onChange` event. This is important for fields like booleans
|
|
28
|
+
* which don't have a `onBlur` event (which is used to set the `touched` state).
|
|
29
|
+
*/
|
|
30
|
+
readonly onlyValidateAfterTouched: boolean;
|
|
24
31
|
protected constructor(options: FieldOptions<TValue>);
|
|
25
32
|
static getFieldCreationSchema(): AnyField[];
|
|
26
33
|
protected isBlank(value: TValue): boolean;
|
|
34
|
+
getValueFromChangeEvent(event: React.ChangeEvent<HTMLInputElement>): TValue;
|
|
27
35
|
getError(value: TValue, allValues?: Form): string | undefined;
|
|
28
36
|
protected _serialize(): BaseSerializedField<TIdentifier>;
|
|
29
37
|
abstract serialize(): ISerializedOnlyField;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { ISerializedField, SerializedBooleanField } from "@overmap-ai/core";
|
|
2
|
+
import { BaseField, ChildFieldOptions } from "../BaseField";
|
|
3
|
+
import { ChangeEvent, ReactNode } from "react";
|
|
4
|
+
import { ComponentProps } from "../typings";
|
|
5
|
+
import { CheckCircledIcon } from "@overmap-ai/blocks";
|
|
6
|
+
export declare class BooleanField extends BaseField<boolean, "boolean"> {
|
|
7
|
+
static readonly fieldTypeName = "Checkbox";
|
|
8
|
+
static readonly fieldTypeDescription = "Perfect for both optional and required yes/no questions.";
|
|
9
|
+
readonly onlyValidateAfterTouched = false;
|
|
10
|
+
static Icon: typeof CheckCircledIcon;
|
|
11
|
+
constructor(options: ChildFieldOptions<boolean>);
|
|
12
|
+
protected isBlank(value: boolean): boolean;
|
|
13
|
+
getValueFromChangeEvent(event: ChangeEvent<HTMLInputElement> | boolean): boolean;
|
|
14
|
+
serialize(): SerializedBooleanField;
|
|
15
|
+
static deserialize(data: ISerializedField): BooleanField;
|
|
16
|
+
getInput(props: ComponentProps<BooleanField>): ReactNode;
|
|
17
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { ISerializedField, SerializedDateField } from "@overmap-ai/core";
|
|
2
|
+
import { BaseField, ChildFieldOptions } from "../BaseField";
|
|
3
|
+
import { GetInputProps } from "../typings";
|
|
4
|
+
import React from "react";
|
|
5
|
+
import { CalendarIcon } from "@overmap-ai/blocks";
|
|
6
|
+
export declare class DateField extends BaseField<string, "date"> {
|
|
7
|
+
static readonly fieldTypeName = "Date";
|
|
8
|
+
static readonly fieldTypeDescription = "Allows specifying a date.";
|
|
9
|
+
static Icon: typeof CalendarIcon;
|
|
10
|
+
readonly onlyValidateAfterTouched = false;
|
|
11
|
+
constructor(options: ChildFieldOptions<string>);
|
|
12
|
+
serialize(): SerializedDateField;
|
|
13
|
+
getValueFromChangeEvent(event: React.ChangeEvent<HTMLInputElement>): string;
|
|
14
|
+
static deserialize(data: ISerializedField): DateField;
|
|
15
|
+
getInput(props: GetInputProps<this>): React.ReactNode;
|
|
16
|
+
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
1
2
|
import { ComponentProps } from '../typings';
|
|
2
|
-
import React from "react";
|
|
3
3
|
import { DateField } from "./DateField";
|
|
4
|
-
export declare const DateInput:
|
|
4
|
+
export declare const DateInput: import("react").NamedExoticComponent<ComponentProps<DateField>>;
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { BaseField, ChildFieldOptions } from "../BaseField";
|
|
2
|
+
import { ISerializedField, SelectFieldOption, SerializedMultiStringField } from "@overmap-ai/core";
|
|
3
|
+
import { GetInputProps, InputFieldLevelValidator } from "../typings.ts";
|
|
4
|
+
import { ReactNode } from "react";
|
|
5
|
+
import { ListBulletIcon } from "@overmap-ai/blocks";
|
|
6
|
+
type MultiStringFieldOptions = ChildFieldOptions<SelectFieldOption[]> & {
|
|
7
|
+
minimum_length?: number;
|
|
8
|
+
maximum_length?: number;
|
|
9
|
+
};
|
|
10
|
+
/**
|
|
11
|
+
* A field that lets the user input multiple strings. Each string must be unique. Useful for things like:
|
|
12
|
+
* - Specifying the options of a SelectField (used in `SelectField.getFieldCreationSchema`
|
|
13
|
+
* - Listing serial numbers and similar
|
|
14
|
+
*/
|
|
15
|
+
export declare class MultiStringField extends BaseField<SelectFieldOption[], "multi-string"> {
|
|
16
|
+
static readonly fieldTypeName = "Multi-string";
|
|
17
|
+
static readonly fieldTypeDescription = "Allows the user to provide multiple unique strings.";
|
|
18
|
+
readonly minLength: number;
|
|
19
|
+
readonly maxLength: number;
|
|
20
|
+
readonly onlyValidateAfterTouched = false;
|
|
21
|
+
static Icon: typeof ListBulletIcon;
|
|
22
|
+
constructor(options: MultiStringFieldOptions);
|
|
23
|
+
getValueFromChangeEvent(event: React.ChangeEvent<HTMLInputElement> | SelectFieldOption[]): SelectFieldOption[];
|
|
24
|
+
getInput(props: GetInputProps<this>): ReactNode;
|
|
25
|
+
serialize(): SerializedMultiStringField;
|
|
26
|
+
protected isBlank(value: SelectFieldOption[]): boolean;
|
|
27
|
+
getFieldValidators(): InputFieldLevelValidator<SelectFieldOption[]>[];
|
|
28
|
+
static deserialize(data: ISerializedField): MultiStringField;
|
|
29
|
+
}
|
|
30
|
+
export {};
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { ISerializedField, SerializedNumberField } from "@overmap-ai/core";
|
|
2
|
+
import { BooleanField } from "../BooleanField";
|
|
3
|
+
import { BaseField, ChildFieldOptions } from "../BaseField";
|
|
4
|
+
import { GetInputProps, InputFieldLevelValidator, InputValidator } from "../typings";
|
|
5
|
+
import { ChangeEvent, ReactNode } from "react";
|
|
6
|
+
import { FontFamilyIcon } from "@overmap-ai/blocks";
|
|
7
|
+
export type NumberFieldValue = number | "";
|
|
8
|
+
export interface NumberFieldOptions extends ChildFieldOptions<NumberFieldValue> {
|
|
9
|
+
maximum?: number;
|
|
10
|
+
minimum?: number;
|
|
11
|
+
integers?: boolean;
|
|
12
|
+
}
|
|
13
|
+
export declare class NumberField extends BaseField<NumberFieldValue, "number"> {
|
|
14
|
+
static readonly fieldTypeName = "Number";
|
|
15
|
+
static readonly fieldTypeDescription = "Allows specifying a number within a given range.";
|
|
16
|
+
readonly minimum: number | undefined;
|
|
17
|
+
readonly maximum: number | undefined;
|
|
18
|
+
readonly integers: boolean;
|
|
19
|
+
static Icon: typeof FontFamilyIcon;
|
|
20
|
+
constructor(options: NumberFieldOptions);
|
|
21
|
+
getValueFromChangeEvent(event: ChangeEvent<HTMLInputElement>): NumberFieldValue;
|
|
22
|
+
static _validateMin: InputValidator<NumberFieldValue>;
|
|
23
|
+
static _validateMax: InputValidator<NumberFieldValue>;
|
|
24
|
+
static getFieldCreationSchema(): (BooleanField | NumberField)[];
|
|
25
|
+
getFieldValidators(): InputFieldLevelValidator<NumberFieldValue>[];
|
|
26
|
+
serialize(): SerializedNumberField;
|
|
27
|
+
static deserialize(data: ISerializedField): NumberField;
|
|
28
|
+
getInput(props: GetInputProps<this>): ReactNode;
|
|
29
|
+
}
|
|
@@ -13,6 +13,7 @@ export interface BaseSelectFieldOptions<TValue, TIdentifier extends "select" | "
|
|
|
13
13
|
}
|
|
14
14
|
export declare abstract class BaseSelectField<TValue extends FieldValue, TIdentifier extends "select" | "multi-select"> extends BaseField<TValue, TIdentifier> {
|
|
15
15
|
readonly options: SelectFieldOption[];
|
|
16
|
+
readonly onlyValidateAfterTouched = false;
|
|
16
17
|
protected constructor(options: BaseSelectFieldOptions<TValue, TIdentifier>);
|
|
17
18
|
protected _serialize(): {
|
|
18
19
|
options: SelectFieldOption[];
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { ISerializedField, SelectFieldOptionValue, SerializedMultiSelectField } from "@overmap-ai/core";
|
|
2
|
+
import { ReactNode } from "react";
|
|
3
|
+
import { GetInputProps } from "../typings";
|
|
4
|
+
import { BaseSelectField, BaseSelectFieldOptions } from "./BaseSelectField";
|
|
5
|
+
import { CheckboxIcon } from "@overmap-ai/blocks";
|
|
6
|
+
/**
|
|
7
|
+
* The options passed to the constructor of MultiSelectField.
|
|
8
|
+
*/
|
|
9
|
+
export type MultiSelectFieldOptions = Omit<BaseSelectFieldOptions<SelectFieldOptionValue[], "multi-select">, "type">;
|
|
10
|
+
export declare class MultiSelectField extends BaseSelectField<SelectFieldOptionValue[], "multi-select"> {
|
|
11
|
+
static readonly fieldTypeName = "Multi-select";
|
|
12
|
+
static readonly fieldTypeDescription = "Allows the user to select a multiple options from a list of options.";
|
|
13
|
+
static Icon: typeof CheckboxIcon;
|
|
14
|
+
constructor(options: MultiSelectFieldOptions);
|
|
15
|
+
getValueFromChangeEvent(event: React.ChangeEvent<HTMLInputElement> | string[]): string[];
|
|
16
|
+
protected isBlank(value: SelectFieldOptionValue[]): boolean;
|
|
17
|
+
serialize(): SerializedMultiSelectField;
|
|
18
|
+
static deserialize(data: ISerializedField): MultiSelectField;
|
|
19
|
+
getInput(props: GetInputProps<this>): ReactNode;
|
|
20
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { ISerializedField, SelectFieldOptionValue, SerializedSelectField } from "@overmap-ai/core";
|
|
2
|
+
import { ReactNode } from "react";
|
|
3
|
+
import { GetInputProps } from "../typings";
|
|
4
|
+
import { BaseSelectField, BaseSelectFieldOptions } from "./BaseSelectField";
|
|
5
|
+
import { DropdownMenuIcon } from "@overmap-ai/blocks";
|
|
6
|
+
/**
|
|
7
|
+
* The options passed to the constructor of SelectField.
|
|
8
|
+
*/
|
|
9
|
+
export type SelectFieldOptions = Omit<BaseSelectFieldOptions<SelectFieldOptionValue, "select">, "type">;
|
|
10
|
+
export declare class SelectField extends BaseSelectField<SelectFieldOptionValue, "select"> {
|
|
11
|
+
static readonly fieldTypeName = "Dropdown";
|
|
12
|
+
static readonly fieldTypeDescription = "Allows the user to select a single option from a list of options.";
|
|
13
|
+
static Icon: typeof DropdownMenuIcon;
|
|
14
|
+
constructor(options: SelectFieldOptions);
|
|
15
|
+
getValueFromChangeEvent(event: React.ChangeEvent<HTMLInputElement> | string): SelectFieldOptionValue;
|
|
16
|
+
serialize(): SerializedSelectField;
|
|
17
|
+
static deserialize(data: ISerializedField): SelectField;
|
|
18
|
+
getInput(props: GetInputProps<this>): ReactNode;
|
|
19
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { ISerializedField, SerializedStringField, StringInputType } from "@overmap-ai/core";
|
|
2
|
+
import { StringOrTextField, StringOrTextFieldOptions } from "../StringOrTextField";
|
|
3
|
+
import { GetInputProps } from "../../typings";
|
|
4
|
+
import React from "react";
|
|
5
|
+
import { InputIcon } from "@overmap-ai/blocks";
|
|
6
|
+
interface StringFieldOptions extends Omit<StringOrTextFieldOptions, "type"> {
|
|
7
|
+
inputType?: StringInputType;
|
|
8
|
+
}
|
|
9
|
+
export declare class StringField extends StringOrTextField<"string"> {
|
|
10
|
+
static readonly fieldTypeName = "Short Text";
|
|
11
|
+
static readonly fieldTypeDescription = "Short text fields can hold up to 500 characters on a single line.";
|
|
12
|
+
readonly inputType: StringInputType;
|
|
13
|
+
static Icon: typeof InputIcon;
|
|
14
|
+
constructor(options: StringFieldOptions);
|
|
15
|
+
serialize(): SerializedStringField;
|
|
16
|
+
static deserialize(data: ISerializedField): StringField;
|
|
17
|
+
getInput(props: GetInputProps<this>): React.ReactNode;
|
|
18
|
+
}
|
|
19
|
+
export {};
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { ISerializedField, SerializedTextField } from "@overmap-ai/core";
|
|
2
|
+
import { StringOrTextField, StringOrTextFieldOptions } from "../StringOrTextField";
|
|
3
|
+
import { GetInputProps } from "../../typings";
|
|
4
|
+
import React from "react";
|
|
5
|
+
import { RowsIcon } from "@overmap-ai/blocks";
|
|
6
|
+
export interface TextFieldOptions extends Omit<StringOrTextFieldOptions, "type"> {
|
|
7
|
+
}
|
|
8
|
+
export declare class TextField extends StringOrTextField<"text"> {
|
|
9
|
+
static readonly fieldTypeName = "Paragraph";
|
|
10
|
+
static readonly fieldTypeDescription = "Paragraph fields can hold up to 5000 characters and can have multiple lines.";
|
|
11
|
+
static Icon: typeof RowsIcon;
|
|
12
|
+
constructor(options: TextFieldOptions);
|
|
13
|
+
serialize(): SerializedTextField;
|
|
14
|
+
static deserialize(data: ISerializedField): TextField;
|
|
15
|
+
getInput(props: GetInputProps<this>): React.ReactNode;
|
|
16
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { ISerializedField, SerializedUploadField } from "@overmap-ai/core";
|
|
2
|
+
import { BaseField, ChildFieldOptions } from "../BaseField";
|
|
3
|
+
import { GetInputProps, InputFieldLevelValidator } from "../typings";
|
|
4
|
+
import { ChangeEvent, ReactNode } from "react";
|
|
5
|
+
import { UploadIcon } from "@overmap-ai/blocks";
|
|
6
|
+
import { NumberField } from "../NumberField";
|
|
7
|
+
import { MultiSelectField } from "../SelectField";
|
|
8
|
+
export interface UploadFieldOptions extends ChildFieldOptions<File[]> {
|
|
9
|
+
extensions?: string[];
|
|
10
|
+
maximum_size?: number | string;
|
|
11
|
+
maximum_files?: number | string;
|
|
12
|
+
}
|
|
13
|
+
export declare class UploadField extends BaseField<File[], "upload"> {
|
|
14
|
+
static readonly fieldTypeName = "Upload";
|
|
15
|
+
static readonly fieldTypeDescription = "Allows a file to be uploaded.";
|
|
16
|
+
readonly extensions?: string[];
|
|
17
|
+
readonly maxFileSize: number | undefined;
|
|
18
|
+
readonly maxFiles: number;
|
|
19
|
+
readonly onlyValidateAfterTouched = false;
|
|
20
|
+
static Icon: typeof UploadIcon;
|
|
21
|
+
constructor(options: UploadFieldOptions);
|
|
22
|
+
getValueFromChangeEvent(event: ChangeEvent<HTMLInputElement>): File[];
|
|
23
|
+
protected isBlank(value: File[]): boolean;
|
|
24
|
+
static getFieldCreationSchema(): (NumberField | MultiSelectField)[];
|
|
25
|
+
getFieldValidators(): InputFieldLevelValidator<File[]>[];
|
|
26
|
+
serialize(): SerializedUploadField;
|
|
27
|
+
static deserialize(data: ISerializedField): UploadField;
|
|
28
|
+
getInput(props: GetInputProps<this>): ReactNode;
|
|
29
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const convertBytesToLargestUnit: (bytes: number) => string;
|
|
@@ -5,6 +5,7 @@ import { NumberField } from "./NumberField";
|
|
|
5
5
|
import { MultiSelectField, SelectField } from "./SelectField";
|
|
6
6
|
import { CustomField } from "./CustomField";
|
|
7
7
|
import { MultiStringField } from "./MultiStringField";
|
|
8
|
+
import { UploadField } from "./UploadField";
|
|
8
9
|
export declare const FieldTypeToClsMapping: {
|
|
9
10
|
readonly date: typeof DateField;
|
|
10
11
|
readonly number: typeof NumberField;
|
|
@@ -13,6 +14,7 @@ export declare const FieldTypeToClsMapping: {
|
|
|
13
14
|
readonly string: typeof StringField;
|
|
14
15
|
readonly text: typeof TextField;
|
|
15
16
|
readonly custom: typeof CustomField;
|
|
17
|
+
readonly upload: typeof UploadField;
|
|
16
18
|
readonly "multi-string": typeof MultiStringField;
|
|
17
19
|
readonly "multi-select": typeof MultiSelectField;
|
|
18
20
|
};
|
package/dist/fields/utils.d.ts
CHANGED
|
@@ -9,4 +9,5 @@ export declare const deserializeField: (serializedField: ISerializedOnlyField) =
|
|
|
9
9
|
export declare const deserialize: (serialized: ISerializedField) => AnyField | FieldSection;
|
|
10
10
|
export type PartialFormRevision = Pick<UserFormRevision, "title" | "fields" | "description"> & Partial<UserFormRevision>;
|
|
11
11
|
export declare function formRevisionToSchema(formRevision: PartialFormRevision, meta?: Partial<SchemaMeta>): ISchema;
|
|
12
|
-
export declare function
|
|
12
|
+
export declare function valueIsFile(v: FieldValue | Promise<File>[] | undefined): v is File[] | Promise<File>[];
|
|
13
|
+
export declare function isConditionMet<TValue extends FieldValue | Promise<File>[]>(condition: TValue extends FieldValue ? SerializedCondition<TValue> | null : null, value: TValue): boolean;
|