@overmap-ai/forms 1.0.1 → 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.
@@ -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;
@@ -1,14 +1,16 @@
1
1
  import { ISerializedField, SerializedBooleanField } from "@overmap-ai/core";
2
2
  import { BaseField, ChildFieldOptions } from "../BaseField";
3
- import { ReactNode } from "react";
3
+ import { ChangeEvent, ReactNode } from "react";
4
4
  import { ComponentProps } from "../typings";
5
5
  import { CheckCircledIcon } from "@overmap-ai/blocks";
6
6
  export declare class BooleanField extends BaseField<boolean, "boolean"> {
7
7
  static readonly fieldTypeName = "Checkbox";
8
8
  static readonly fieldTypeDescription = "Perfect for both optional and required yes/no questions.";
9
+ readonly onlyValidateAfterTouched = false;
9
10
  static Icon: typeof CheckCircledIcon;
10
11
  constructor(options: ChildFieldOptions<boolean>);
11
12
  protected isBlank(value: boolean): boolean;
13
+ getValueFromChangeEvent(event: ChangeEvent<HTMLInputElement> | boolean): boolean;
12
14
  serialize(): SerializedBooleanField;
13
15
  static deserialize(data: ISerializedField): BooleanField;
14
16
  getInput(props: ComponentProps<BooleanField>): ReactNode;
@@ -7,8 +7,10 @@ export declare class DateField extends BaseField<string, "date"> {
7
7
  static readonly fieldTypeName = "Date";
8
8
  static readonly fieldTypeDescription = "Allows specifying a date.";
9
9
  static Icon: typeof CalendarIcon;
10
+ readonly onlyValidateAfterTouched = false;
10
11
  constructor(options: ChildFieldOptions<string>);
11
12
  serialize(): SerializedDateField;
13
+ getValueFromChangeEvent(event: React.ChangeEvent<HTMLInputElement>): string;
12
14
  static deserialize(data: ISerializedField): DateField;
13
15
  getInput(props: GetInputProps<this>): React.ReactNode;
14
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: React.NamedExoticComponent<ComponentProps<DateField>>;
4
+ export declare const DateInput: import("react").NamedExoticComponent<ComponentProps<DateField>>;
@@ -17,8 +17,10 @@ export declare class MultiStringField extends BaseField<SelectFieldOption[], "mu
17
17
  static readonly fieldTypeDescription = "Allows the user to provide multiple unique strings.";
18
18
  readonly minLength: number;
19
19
  readonly maxLength: number;
20
+ readonly onlyValidateAfterTouched = false;
20
21
  static Icon: typeof ListBulletIcon;
21
22
  constructor(options: MultiStringFieldOptions);
23
+ getValueFromChangeEvent(event: React.ChangeEvent<HTMLInputElement> | SelectFieldOption[]): SelectFieldOption[];
22
24
  getInput(props: GetInputProps<this>): ReactNode;
23
25
  serialize(): SerializedMultiStringField;
24
26
  protected isBlank(value: SelectFieldOption[]): boolean;
@@ -2,7 +2,7 @@ import { ISerializedField, SerializedNumberField } from "@overmap-ai/core";
2
2
  import { BooleanField } from "../BooleanField";
3
3
  import { BaseField, ChildFieldOptions } from "../BaseField";
4
4
  import { GetInputProps, InputFieldLevelValidator, InputValidator } from "../typings";
5
- import { ReactNode } from "react";
5
+ import { ChangeEvent, ReactNode } from "react";
6
6
  import { FontFamilyIcon } from "@overmap-ai/blocks";
7
7
  export type NumberFieldValue = number | "";
8
8
  export interface NumberFieldOptions extends ChildFieldOptions<NumberFieldValue> {
@@ -18,6 +18,7 @@ export declare class NumberField extends BaseField<NumberFieldValue, "number"> {
18
18
  readonly integers: boolean;
19
19
  static Icon: typeof FontFamilyIcon;
20
20
  constructor(options: NumberFieldOptions);
21
+ getValueFromChangeEvent(event: ChangeEvent<HTMLInputElement>): NumberFieldValue;
21
22
  static _validateMin: InputValidator<NumberFieldValue>;
22
23
  static _validateMax: InputValidator<NumberFieldValue>;
23
24
  static getFieldCreationSchema(): (BooleanField | NumberField)[];
@@ -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[];
@@ -12,6 +12,7 @@ export declare class MultiSelectField extends BaseSelectField<SelectFieldOptionV
12
12
  static readonly fieldTypeDescription = "Allows the user to select a multiple options from a list of options.";
13
13
  static Icon: typeof CheckboxIcon;
14
14
  constructor(options: MultiSelectFieldOptions);
15
+ getValueFromChangeEvent(event: React.ChangeEvent<HTMLInputElement> | string[]): string[];
15
16
  protected isBlank(value: SelectFieldOptionValue[]): boolean;
16
17
  serialize(): SerializedMultiSelectField;
17
18
  static deserialize(data: ISerializedField): MultiSelectField;
@@ -12,6 +12,7 @@ export declare class SelectField extends BaseSelectField<SelectFieldOptionValue,
12
12
  static readonly fieldTypeDescription = "Allows the user to select a single option from a list of options.";
13
13
  static Icon: typeof DropdownMenuIcon;
14
14
  constructor(options: SelectFieldOptions);
15
+ getValueFromChangeEvent(event: React.ChangeEvent<HTMLInputElement> | string): SelectFieldOptionValue;
15
16
  serialize(): SerializedSelectField;
16
17
  static deserialize(data: ISerializedField): SelectField;
17
18
  getInput(props: GetInputProps<this>): ReactNode;
@@ -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,4 @@
1
+ /// <reference types="react" />
2
+ import { ComponentProps } from '../typings';
3
+ import { UploadField } from "./UploadField";
4
+ export declare const NumberInput: import("react").NamedExoticComponent<ComponentProps<UploadField>>;
@@ -0,0 +1,2 @@
1
+ export * from "./UploadField";
2
+ export * from "./UploadInput";
@@ -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
  };
@@ -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 isConditionMet<TValue extends FieldValue>(condition: SerializedCondition<TValue> | null, value: TValue): boolean;
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;