@xyo-network/react-form-group 4.4.9 → 4.4.11
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/browser/FormGroup.d.ts +49 -0
- package/dist/browser/FormGroup.d.ts.map +1 -0
- package/dist/browser/InputError.d.ts +5 -0
- package/dist/browser/InputError.d.ts.map +1 -0
- package/dist/browser/context/Context.d.ts +3 -0
- package/dist/browser/context/Context.d.ts.map +1 -0
- package/dist/browser/context/Provider.d.ts +11 -0
- package/dist/browser/context/Provider.d.ts.map +1 -0
- package/dist/browser/context/State.d.ts +7 -0
- package/dist/browser/context/State.d.ts.map +1 -0
- package/dist/browser/context/index.d.ts +5 -0
- package/dist/browser/context/index.d.ts.map +1 -0
- package/dist/browser/context/use.d.ts +2 -0
- package/dist/browser/context/use.d.ts.map +1 -0
- package/dist/browser/control/AbstractControl.d.ts +74 -0
- package/dist/browser/control/AbstractControl.d.ts.map +1 -0
- package/dist/browser/control/FormControl.d.ts +25 -0
- package/dist/browser/control/FormControl.d.ts.map +1 -0
- package/dist/browser/control/FormControlBase.d.ts +32 -0
- package/dist/browser/control/FormControlBase.d.ts.map +1 -0
- package/dist/browser/control/accessor/ControlValueAccessor.d.ts +21 -0
- package/dist/browser/control/accessor/ControlValueAccessor.d.ts.map +1 -0
- package/dist/browser/control/accessor/ControlValueAccessorBase.d.ts +109 -0
- package/dist/browser/control/accessor/ControlValueAccessorBase.d.ts.map +1 -0
- package/dist/browser/control/accessor/FormControlStatus.d.ts +33 -0
- package/dist/browser/control/accessor/FormControlStatus.d.ts.map +1 -0
- package/dist/browser/control/accessor/ValidControlValue.d.ts +2 -0
- package/dist/browser/control/accessor/ValidControlValue.d.ts.map +1 -0
- package/dist/browser/control/accessor/index.d.ts +5 -0
- package/dist/browser/control/accessor/index.d.ts.map +1 -0
- package/dist/browser/control/index.d.ts +5 -0
- package/dist/browser/control/index.d.ts.map +1 -0
- package/dist/browser/index.d.ts +6 -218
- package/dist/browser/index.d.ts.map +1 -0
- package/dist/browser/storage/ArchivistFormGroupStorage.d.ts +11 -0
- package/dist/browser/storage/ArchivistFormGroupStorage.d.ts.map +1 -0
- package/dist/browser/storage/FormGroupStorage.d.ts +8 -0
- package/dist/browser/storage/FormGroupStorage.d.ts.map +1 -0
- package/dist/browser/storage/index.d.ts +3 -0
- package/dist/browser/storage/index.d.ts.map +1 -0
- package/package.json +14 -14
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import type { Payload } from '@xyo-network/payload-model';
|
|
2
|
+
import { AbstractControl } from './control/index.ts';
|
|
3
|
+
import type { ErrorSummary } from './InputError.ts';
|
|
4
|
+
import type { FormGroupStorage } from './storage/index.ts';
|
|
5
|
+
export type PayloadWithTimestamp = Payload<{
|
|
6
|
+
timestamp?: number;
|
|
7
|
+
}>;
|
|
8
|
+
export type KeyOfString<T> = keyof T extends string ? keyof T : never;
|
|
9
|
+
type FormGroupErrors<TValue> = Record<KeyOfString<TValue>, string>;
|
|
10
|
+
export type FormGroupParams<TStorageValue extends Payload = Payload> = {
|
|
11
|
+
serialize?: boolean;
|
|
12
|
+
storage?: {
|
|
13
|
+
sensitive?: FormGroupStorage<TStorageValue>;
|
|
14
|
+
storage?: FormGroupStorage<TStorageValue>;
|
|
15
|
+
};
|
|
16
|
+
ttlStorage?: number;
|
|
17
|
+
};
|
|
18
|
+
/**
|
|
19
|
+
* Organize form controls in a group.
|
|
20
|
+
*
|
|
21
|
+
* NOTE: This is a work in progress and only supports top level controls. Nested controls are not supported.
|
|
22
|
+
*/
|
|
23
|
+
export declare class FormGroup<TValue extends PayloadWithTimestamp = PayloadWithTimestamp, TStorageValue extends PayloadWithTimestamp = PayloadWithTimestamp> extends AbstractControl {
|
|
24
|
+
private fgParams?;
|
|
25
|
+
private _controls;
|
|
26
|
+
private serializeListeners;
|
|
27
|
+
private serializedSensitiveState;
|
|
28
|
+
private serializedState;
|
|
29
|
+
constructor(fgParams?: FormGroupParams<TStorageValue> | undefined);
|
|
30
|
+
get errorSummary(): ErrorSummary;
|
|
31
|
+
get errors(): FormGroupErrors<TValue>;
|
|
32
|
+
get nonSensitiveStorage(): FormGroupStorage<TStorageValue> | undefined;
|
|
33
|
+
get sensitiveStorage(): FormGroupStorage<TStorageValue> | undefined;
|
|
34
|
+
get touched(): boolean;
|
|
35
|
+
get valid(): boolean;
|
|
36
|
+
get values(): TValue;
|
|
37
|
+
getControl(name: string): Record<KeyOfString<TValue>, AbstractControl<import("./control/index.ts").ValidControlValue>>[KeyOfString<TValue>];
|
|
38
|
+
getSerializedValue(name: string, sensitive?: boolean): Promise<string | undefined>;
|
|
39
|
+
registerControl(name: string, control: AbstractControl): void;
|
|
40
|
+
resetControls(): void;
|
|
41
|
+
resetValues(): void;
|
|
42
|
+
unregisterControl(name: string): void;
|
|
43
|
+
validateFields(requiredFields?: string[] | undefined): void;
|
|
44
|
+
private serializeControlValue;
|
|
45
|
+
private serializeValues;
|
|
46
|
+
private setStateValueFromStorage;
|
|
47
|
+
}
|
|
48
|
+
export {};
|
|
49
|
+
//# sourceMappingURL=FormGroup.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"FormGroup.d.ts","sourceRoot":"","sources":["../../src/FormGroup.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,4BAA4B,CAAA;AAGzD,OAAO,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAA;AACpD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAA;AACnD,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAA;AAE1D,MAAM,MAAM,oBAAoB,GAAG,OAAO,CAAC;IAAE,SAAS,CAAC,EAAE,MAAM,CAAA;CAAE,CAAC,CAAA;AAElE,MAAM,MAAM,WAAW,CAAC,CAAC,IAAI,MAAM,CAAC,SAAS,MAAM,GAAG,MAAM,CAAC,GAAG,KAAK,CAAA;AAErE,KAAK,eAAe,CAAC,MAAM,IAAI,MAAM,CAAC,WAAW,CAAC,MAAM,CAAC,EAAE,MAAM,CAAC,CAAA;AAElE,MAAM,MAAM,eAAe,CAAC,aAAa,SAAS,OAAO,GAAG,OAAO,IAAI;IACrE,SAAS,CAAC,EAAE,OAAO,CAAA;IACnB,OAAO,CAAC,EAAE;QACR,SAAS,CAAC,EAAE,gBAAgB,CAAC,aAAa,CAAC,CAAA;QAC3C,OAAO,CAAC,EAAE,gBAAgB,CAAC,aAAa,CAAC,CAAA;KAC1C,CAAA;IACD,UAAU,CAAC,EAAE,MAAM,CAAA;CACpB,CAAA;AAID;;;;GAIG;AACH,qBAAa,SAAS,CACpB,MAAM,SAAS,oBAAoB,GAAG,oBAAoB,EAC1D,aAAa,SAAS,oBAAoB,GAAG,oBAAoB,CACjE,SAAQ,eAAe;IAQX,OAAO,CAAC,QAAQ,CAAC;IAP7B,OAAO,CAAC,SAAS,CAAqD;IAEtE,OAAO,CAAC,kBAAkB,CAA+C;IAEzE,OAAO,CAAC,wBAAwB,CAAmD;IACnF,OAAO,CAAC,eAAe,CAAmD;gBAEtD,QAAQ,CAAC,EAAE,eAAe,CAAC,aAAa,CAAC,YAAA;IAI7D,IAAI,YAAY,iBAaf;IAED,IAAI,MAAM,IAAI,eAAe,CAAC,MAAM,CAAC,CAOpC;IAED,IAAI,mBAAmB,gDAEtB;IAED,IAAI,gBAAgB,gDAEnB;IAED,IAAa,OAAO,YAEnB;IAED,IAAa,KAAK,YAEjB;IAED,IAAI,MAAM,IAAI,MAAM,CAOnB;IAED,UAAU,CAAC,IAAI,EAAE,MAAM;IAIjB,kBAAkB,CAAC,IAAI,EAAE,MAAM,EAAE,SAAS,UAAQ,GAAG,OAAO,CAAC,MAAM,GAAG,SAAS,CAAC;IAwBtF,eAAe,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,eAAe;IAMtD,aAAa;IAMb,WAAW;IAMX,iBAAiB,CAAC,IAAI,EAAE,MAAM;IAW9B,cAAc,CAAC,cAAc,CAAC,EAAE,MAAM,EAAE,GAAG,SAAS;IAWpD,OAAO,CAAC,qBAAqB;IAuC7B,OAAO,CAAC,eAAe;IAUvB,OAAO,CAAC,wBAAwB;CAcjC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"InputError.d.ts","sourceRoot":"","sources":["../../src/InputError.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,YAAY,GAAG;IACzB,YAAY,EAAE,MAAM,CAAA;IACpB,aAAa,EAAE,MAAM,EAAE,CAAA;CACxB,CAAA"}
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import type { FormGroupContextWithPayloadState } from './State.ts';
|
|
2
|
+
export declare const FormGroupBaseContext: import("react").Context<FormGroupContextWithPayloadState<import("@xyo-network/payload-model").Payload, import("@xyo-network/payload-model").Payload> & import("@xyo-network/react-shared").ContextExState>;
|
|
3
|
+
//# sourceMappingURL=Context.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Context.d.ts","sourceRoot":"","sources":["../../../src/context/Context.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,gCAAgC,EAAE,MAAM,YAAY,CAAA;AAElE,eAAO,MAAM,oBAAoB,4MAAsD,CAAA"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { Payload } from '@xyo-network/payload-model';
|
|
2
|
+
import type { PropsWithChildren } from 'react';
|
|
3
|
+
import type { FormGroupParams } from '../FormGroup.ts';
|
|
4
|
+
export interface FormGroupPayloadProviderProps<TStorage extends Payload = Payload> extends PropsWithChildren {
|
|
5
|
+
params?: FormGroupParams<TStorage>;
|
|
6
|
+
}
|
|
7
|
+
/**
|
|
8
|
+
* Provides a FormGroup to child components.
|
|
9
|
+
*/
|
|
10
|
+
export declare const FormGroupPayloadProvider: ({ children, params, ...props }: FormGroupPayloadProviderProps) => import("react/jsx-runtime").JSX.Element;
|
|
11
|
+
//# sourceMappingURL=Provider.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Provider.d.ts","sourceRoot":"","sources":["../../../src/context/Provider.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,4BAA4B,CAAA;AACzD,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,OAAO,CAAA;AAG9C,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAA;AAItD,MAAM,WAAW,6BAA6B,CAAC,QAAQ,SAAS,OAAO,GAAG,OAAO,CAAE,SAAQ,iBAAiB;IAC1G,MAAM,CAAC,EAAE,eAAe,CAAC,QAAQ,CAAC,CAAA;CACnC;AAED;;GAEG;AACH,eAAO,MAAM,wBAAwB,GAAI,gCAEtC,6BAA6B,4CAiB/B,CAAA"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { Payload } from '@xyo-network/payload-model';
|
|
2
|
+
import type { ContextExState } from '@xyo-network/react-shared';
|
|
3
|
+
import type { FormGroup } from '../FormGroup.ts';
|
|
4
|
+
export interface FormGroupContextWithPayloadState<TValue extends Payload = Payload, TStorageValue extends Payload = Payload> extends ContextExState {
|
|
5
|
+
formGroup?: FormGroup<TValue, TStorageValue>;
|
|
6
|
+
}
|
|
7
|
+
//# sourceMappingURL=State.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"State.d.ts","sourceRoot":"","sources":["../../../src/context/State.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,4BAA4B,CAAA;AACzD,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,2BAA2B,CAAA;AAE/D,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAA;AAEhD,MAAM,WAAW,gCAAgC,CAAC,MAAM,SAAS,OAAO,GAAG,OAAO,EAAE,aAAa,SAAS,OAAO,GAAG,OAAO,CAAE,SAAQ,cAAc;IACjJ,SAAS,CAAC,EAAE,SAAS,CAAC,MAAM,EAAE,aAAa,CAAC,CAAA;CAC7C"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/context/index.ts"],"names":[],"mappings":"AAAA,cAAc,cAAc,CAAA;AAC5B,cAAc,gBAAgB,CAAA;AAC9B,cAAc,YAAY,CAAA;AAC1B,cAAc,UAAU,CAAA"}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
export declare const useFormGroup: (required?: boolean) => Omit<import("./State.ts").FormGroupContextWithPayloadState<import("@xyo-network/payload-model").Payload, import("@xyo-network/payload-model").Payload> & import("@xyo-network/react-shared").ContextExState, "provided">;
|
|
2
|
+
//# sourceMappingURL=use.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"use.d.ts","sourceRoot":"","sources":["../../../src/context/use.ts"],"names":[],"mappings":"AAIA,eAAO,MAAM,YAAY,GAAI,kBAAgB,6NAA8D,CAAA"}
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import type { ControlValueAccessorBaseEvents, FormControlStatus, ValidControlValue } from './accessor/index.ts';
|
|
2
|
+
import { ControlValueAccessorBase } from './accessor/index.ts';
|
|
3
|
+
export type AbstractControlEvents<TValue> = ControlValueAccessorBaseEvents<TValue> & {
|
|
4
|
+
statusChanged: {
|
|
5
|
+
status: FormControlStatus;
|
|
6
|
+
};
|
|
7
|
+
};
|
|
8
|
+
/**
|
|
9
|
+
* This is the base class for `Control` classes (i.e. FormControl),
|
|
10
|
+
*
|
|
11
|
+
* It provides some of the shared behavior that all controls and groups of controls have, like
|
|
12
|
+
* running validators, calculating status, and resetting state. It also defines the properties
|
|
13
|
+
* that are shared between all sub-classes, like `value`, `valid`, and `dirty`. It shouldn't be
|
|
14
|
+
* instantiated directly.
|
|
15
|
+
*
|
|
16
|
+
* NOTE: Heavily borrowed from Angular's AbstractControl:
|
|
17
|
+
* https://github.com/angular/angular/blob/5dcdbfcba934a930468aec140a7183b034466bdf/packages/forms/src/model/abstract_model.ts
|
|
18
|
+
*/
|
|
19
|
+
export declare class AbstractControl<TValue extends ValidControlValue = ValidControlValue> extends ControlValueAccessorBase<TValue, AbstractControlEvents<TValue>> {
|
|
20
|
+
private _status;
|
|
21
|
+
constructor();
|
|
22
|
+
/**
|
|
23
|
+
* A control is `disabled` when its `status` is `DISABLED`.
|
|
24
|
+
*
|
|
25
|
+
* Disabled controls are exempt from validation checks and
|
|
26
|
+
* are not included in the aggregate value of their ancestor
|
|
27
|
+
* controls.
|
|
28
|
+
*
|
|
29
|
+
* @returns True if the control is disabled, false otherwise.
|
|
30
|
+
*/
|
|
31
|
+
/** @deprecated - disabled functionality not implemented */
|
|
32
|
+
get disabled(): boolean;
|
|
33
|
+
/**
|
|
34
|
+
* A control is `enabled` as long as its `status` is not `DISABLED`.
|
|
35
|
+
*
|
|
36
|
+
* @returns True if the control has any status other than 'DISABLED',
|
|
37
|
+
* false if the status is 'DISABLED'.
|
|
38
|
+
*/
|
|
39
|
+
get enabled(): boolean;
|
|
40
|
+
/**
|
|
41
|
+
* A control is `invalid` when its `status` is `INVALID`.
|
|
42
|
+
|
|
43
|
+
*
|
|
44
|
+
* @returns True if this control has failed one or more of its validation checks,
|
|
45
|
+
* false otherwise.
|
|
46
|
+
*/
|
|
47
|
+
get invalid(): boolean;
|
|
48
|
+
/**
|
|
49
|
+
* A control is `pending` when its `status` is `PENDING`.
|
|
50
|
+
*
|
|
51
|
+
* @returns True if this control is in the process of conducting a validation check,
|
|
52
|
+
* false otherwise.
|
|
53
|
+
*/
|
|
54
|
+
get pending(): boolean;
|
|
55
|
+
/**
|
|
56
|
+
* The raw value of the control.
|
|
57
|
+
*/
|
|
58
|
+
get rawValue(): TValue;
|
|
59
|
+
/**
|
|
60
|
+
* The current status of the control.
|
|
61
|
+
*/
|
|
62
|
+
get status(): FormControlStatus | undefined;
|
|
63
|
+
/**
|
|
64
|
+
* A control is `valid` when its `status` is `VALID`.
|
|
65
|
+
*
|
|
66
|
+
* @returns True if the control has passed all of its validation tests,
|
|
67
|
+
* false otherwise.
|
|
68
|
+
*/
|
|
69
|
+
get valid(): boolean;
|
|
70
|
+
setErrorAndValidity(error: string, status: FormControlStatus): void;
|
|
71
|
+
setStatus(status: FormControlStatus): void;
|
|
72
|
+
validate(): boolean;
|
|
73
|
+
}
|
|
74
|
+
//# sourceMappingURL=AbstractControl.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"AbstractControl.d.ts","sourceRoot":"","sources":["../../../src/control/AbstractControl.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EACV,8BAA8B,EAC9B,iBAAiB,EACjB,iBAAiB,EAClB,MAAM,qBAAqB,CAAA;AAC5B,OAAO,EACL,wBAAwB,EAKzB,MAAM,qBAAqB,CAAA;AAE5B,MAAM,MAAM,qBAAqB,CAAC,MAAM,IAAI,8BAA8B,CAAC,MAAM,CAAC,GAAG;IACnF,aAAa,EAAE;QAAE,MAAM,EAAE,iBAAiB,CAAA;KAAE,CAAA;CAC7C,CAAA;AAED;;;;;;;;;;GAUG;AACH,qBAAa,eAAe,CAAC,MAAM,SAAS,iBAAiB,GAAG,iBAAiB,CAAE,SAAQ,wBAAwB,CACjH,MAAM,EACN,qBAAqB,CAAC,MAAM,CAAC,CAC9B;IACC,OAAO,CAAC,OAAO,CAA2C;;IAM1D;;;;;;;;OAQG;IACH,2DAA2D;IAC3D,IAAI,QAAQ,IAAI,OAAO,CAEtB;IAED;;;;;OAKG;IACH,IAAI,OAAO,IAAI,OAAO,CAErB;IAED;;;;;;OAMG;IACH,IAAI,OAAO,IAAI,OAAO,CAErB;IAED;;;;;OAKG;IACH,IAAI,OAAO,IAAI,OAAO,CAErB;IAED;;OAEG;IACH,IAAI,QAAQ,IAAI,MAAM,CAErB;IAED;;OAEG;IACH,IAAI,MAAM,kCAET;IAED;;;;;OAKG;IACH,IAAI,KAAK,IAAI,OAAO,CAEnB;IAED,mBAAmB,CAAC,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,iBAAiB;IAK5D,SAAS,CAAC,MAAM,EAAE,iBAAiB;IASnC,QAAQ,IAAI,OAAO;CAGpB"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import type { EmptyObject } from '@xylabs/object';
|
|
2
|
+
import type { AbstractControl } from './AbstractControl.ts';
|
|
3
|
+
export type CursorPosition = {
|
|
4
|
+
current: number | undefined;
|
|
5
|
+
previous: number | undefined;
|
|
6
|
+
};
|
|
7
|
+
export interface FormControlValidator {
|
|
8
|
+
blurError?: (value: string) => void;
|
|
9
|
+
changeError?: (value: string) => void;
|
|
10
|
+
pattern?: RegExp;
|
|
11
|
+
patternStrict?: RegExp;
|
|
12
|
+
required?: boolean;
|
|
13
|
+
}
|
|
14
|
+
export interface FormControlMask {
|
|
15
|
+
cursorPosition: CursorPosition;
|
|
16
|
+
getCursorPosition?: () => number | undefined;
|
|
17
|
+
mask?: (value: string) => string;
|
|
18
|
+
onCursorChange?: (cursor: number | undefined) => void;
|
|
19
|
+
unmask?: (value: string) => string;
|
|
20
|
+
}
|
|
21
|
+
export interface FormControl<TProps extends EmptyObject = EmptyObject> extends FormControlValidator, FormControlMask, AbstractControl {
|
|
22
|
+
readonly name?: string;
|
|
23
|
+
props: TProps;
|
|
24
|
+
}
|
|
25
|
+
//# sourceMappingURL=FormControl.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"FormControl.d.ts","sourceRoot":"","sources":["../../../src/control/FormControl.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAA;AAEjD,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAA;AAE3D,MAAM,MAAM,cAAc,GAAG;IAC3B,OAAO,EAAE,MAAM,GAAG,SAAS,CAAA;IAC3B,QAAQ,EAAE,MAAM,GAAG,SAAS,CAAA;CAC7B,CAAA;AAED,MAAM,WAAW,oBAAoB;IACnC,SAAS,CAAC,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,CAAA;IACnC,WAAW,CAAC,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,CAAA;IAErC,OAAO,CAAC,EAAE,MAAM,CAAA;IAEhB,aAAa,CAAC,EAAE,MAAM,CAAA;IACtB,QAAQ,CAAC,EAAE,OAAO,CAAA;CACnB;AAED,MAAM,WAAW,eAAe;IAC9B,cAAc,EAAE,cAAc,CAAA;IAC9B,iBAAiB,CAAC,EAAE,MAAM,MAAM,GAAG,SAAS,CAAA;IAC5C,IAAI,CAAC,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,MAAM,CAAA;IAChC,cAAc,CAAC,EAAE,CAAC,MAAM,EAAE,MAAM,GAAG,SAAS,KAAK,IAAI,CAAA;IACrD,MAAM,CAAC,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,MAAM,CAAA;CACnC;AAED,MAAM,WAAW,WAAW,CAAC,MAAM,SAAS,WAAW,GAAG,WAAW,CAAE,SAAQ,oBAAoB,EAAE,eAAe,EAAE,eAAe;IACnI,QAAQ,CAAC,IAAI,CAAC,EAAE,MAAM,CAAA;IACtB,KAAK,EAAE,MAAM,CAAA;CACd"}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import type { EmptyObject } from '@xylabs/object';
|
|
2
|
+
import { AbstractControl } from './AbstractControl.ts';
|
|
3
|
+
import type { SetOptions } from './accessor/index.ts';
|
|
4
|
+
import type { CursorPosition, FormControl } from './FormControl.ts';
|
|
5
|
+
/**
|
|
6
|
+
* A base class for form controls and their validation.
|
|
7
|
+
*/
|
|
8
|
+
export declare abstract class FormControlBase<TProps extends EmptyObject = EmptyObject> extends AbstractControl implements FormControl {
|
|
9
|
+
/**
|
|
10
|
+
* The current and previous cursor position of the input element.
|
|
11
|
+
*/
|
|
12
|
+
cursorPosition: CursorPosition;
|
|
13
|
+
invalidMessage: string;
|
|
14
|
+
pattern: RegExp;
|
|
15
|
+
patternStrict: RegExp;
|
|
16
|
+
props: TProps;
|
|
17
|
+
required: boolean;
|
|
18
|
+
private _name;
|
|
19
|
+
constructor();
|
|
20
|
+
get name(): string | undefined;
|
|
21
|
+
get rawValue(): import("./accessor/ValidControlValue.ts").ValidControlValue;
|
|
22
|
+
blurError?(value: string): void | undefined;
|
|
23
|
+
changeError?(value: string): void;
|
|
24
|
+
getCursorPosition?(): number | undefined;
|
|
25
|
+
mask?(value: string): string;
|
|
26
|
+
onCursorChange: (cursor: number | undefined) => void;
|
|
27
|
+
setValue(value: string | undefined, setOptions: SetOptions): void;
|
|
28
|
+
unmask?(value: string): string;
|
|
29
|
+
validate(): boolean;
|
|
30
|
+
protected setName(name: string | undefined): void;
|
|
31
|
+
}
|
|
32
|
+
//# sourceMappingURL=FormControlBase.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"FormControlBase.d.ts","sourceRoot":"","sources":["../../../src/control/FormControlBase.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAA;AAEjD,OAAO,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAA;AACtD,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAA;AACrD,OAAO,KAAK,EAAE,cAAc,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAA;AAInE;;GAEG;AACH,8BAAsB,eAAe,CAAC,MAAM,SAAS,WAAW,GAAG,WAAW,CAAE,SAAQ,eAAgB,YAAW,WAAW;IAC5H;;OAEG;IACH,cAAc,EAAE,cAAc,CAA8C;IAE5E,cAAc,SAAkB;IAChC,OAAO,SAAgB;IACvB,aAAa,SAAgB;IAC7B,KAAK,EAAS,MAAM,CAAA;IACpB,QAAQ,UAAQ;IAEhB,OAAO,CAAC,KAAK,CAAgC;;IAM7C,IAAI,IAAI,uBAEP;IAED,IAAa,QAAQ,gEAEpB;IAED,SAAS,CAAC,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS;IAC3C,WAAW,CAAC,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI;IACjC,iBAAiB,CAAC,IAAI,MAAM,GAAG,SAAS;IACxC,IAAI,CAAC,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM;IAC5B,cAAc,EAAE,CAAC,MAAM,EAAE,MAAM,GAAG,SAAS,KAAK,IAAI,CAAW;IAEtD,QAAQ,CAAC,KAAK,EAAE,MAAM,YAAK,EAAE,UAAU,EAAE,UAAU;IA0B5D,MAAM,CAAC,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM;IAGrB,QAAQ,IAAI,OAAO;IAQ5B,SAAS,CAAC,OAAO,CAAC,IAAI,EAAE,MAAM,GAAG,SAAS;CAG3C"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type { ValidControlValue } from './ValidControlValue.ts';
|
|
2
|
+
export interface SetOptions {
|
|
3
|
+
disableEmit?: boolean;
|
|
4
|
+
}
|
|
5
|
+
export interface ControlSerializeSettings {
|
|
6
|
+
sensitive?: boolean;
|
|
7
|
+
serializable?: boolean;
|
|
8
|
+
}
|
|
9
|
+
export interface ControlValueAccessor<T = ValidControlValue> {
|
|
10
|
+
readonly error: string;
|
|
11
|
+
readonly previousValue: T;
|
|
12
|
+
readonly serializeSettings: ControlSerializeSettings;
|
|
13
|
+
readonly touched: boolean;
|
|
14
|
+
readonly value: T;
|
|
15
|
+
registerOnChange(fn: (value: T) => void): void;
|
|
16
|
+
registerOnErrorChange(fn: (error: string) => void): void;
|
|
17
|
+
registerOnTouched(fn: (isTouched: boolean) => void): void;
|
|
18
|
+
setTouched(isTouched: boolean): void;
|
|
19
|
+
setValue(fieldValue: T, options?: SetOptions): void;
|
|
20
|
+
}
|
|
21
|
+
//# sourceMappingURL=ControlValueAccessor.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ControlValueAccessor.d.ts","sourceRoot":"","sources":["../../../../src/control/accessor/ControlValueAccessor.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAA;AAE/D,MAAM,WAAW,UAAU;IACzB,WAAW,CAAC,EAAE,OAAO,CAAA;CACtB;AAED,MAAM,WAAW,wBAAwB;IACvC,SAAS,CAAC,EAAE,OAAO,CAAA;IACnB,YAAY,CAAC,EAAE,OAAO,CAAA;CACvB;AAED,MAAM,WAAW,oBAAoB,CAAC,CAAC,GAAG,iBAAiB;IACzD,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAA;IACtB,QAAQ,CAAC,aAAa,EAAE,CAAC,CAAA;IACzB,QAAQ,CAAC,iBAAiB,EAAE,wBAAwB,CAAA;IACpD,QAAQ,CAAC,OAAO,EAAE,OAAO,CAAA;IACzB,QAAQ,CAAC,KAAK,EAAE,CAAC,CAAA;IACjB,gBAAgB,CAAC,EAAE,EAAE,CAAC,KAAK,EAAE,CAAC,KAAK,IAAI,GAAG,IAAI,CAAA;IAC9C,qBAAqB,CAAC,EAAE,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,GAAG,IAAI,CAAA;IACxD,iBAAiB,CAAC,EAAE,EAAE,CAAC,SAAS,EAAE,OAAO,KAAK,IAAI,GAAG,IAAI,CAAA;IACzD,UAAU,CAAC,SAAS,EAAE,OAAO,GAAG,IAAI,CAAA;IACpC,QAAQ,CAAC,UAAU,EAAE,CAAC,EAAE,OAAO,CAAC,EAAE,UAAU,GAAG,IAAI,CAAA;CACpD"}
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
import type { BaseParams } from '@xylabs/object';
|
|
2
|
+
import { BaseEmitter } from '@xyo-network/module-event-emitter';
|
|
3
|
+
import type { ControlSerializeSettings, ControlValueAccessor, SetOptions } from './ControlValueAccessor.ts';
|
|
4
|
+
import type { ValidControlValue } from './ValidControlValue.ts';
|
|
5
|
+
export type ControlValueAccessorBaseConfig = {
|
|
6
|
+
disableEvents?: boolean;
|
|
7
|
+
};
|
|
8
|
+
export declare const DefaultSetOptions: SetOptions;
|
|
9
|
+
export type ControlValueAccessorBaseEvents<TValue = ValidControlValue> = {
|
|
10
|
+
errorChanged: {
|
|
11
|
+
error: string;
|
|
12
|
+
};
|
|
13
|
+
touchChanged: {
|
|
14
|
+
touched: boolean;
|
|
15
|
+
};
|
|
16
|
+
valueChanged: {
|
|
17
|
+
value: TValue;
|
|
18
|
+
};
|
|
19
|
+
};
|
|
20
|
+
/**
|
|
21
|
+
* The base class for control value accessors interface
|
|
22
|
+
*/
|
|
23
|
+
export declare class ControlValueAccessorBase<TValue = ValidControlValue, TEventData extends ControlValueAccessorBaseEvents<TValue> = ControlValueAccessorBaseEvents<TValue>> extends BaseEmitter<BaseParams, TEventData> implements ControlValueAccessor<TValue> {
|
|
24
|
+
private config;
|
|
25
|
+
private _error;
|
|
26
|
+
private _previousValue;
|
|
27
|
+
private _serializeSettings;
|
|
28
|
+
private _touched;
|
|
29
|
+
private _value;
|
|
30
|
+
constructor(config: ControlValueAccessorBaseConfig);
|
|
31
|
+
/**
|
|
32
|
+
* The error message for the control.
|
|
33
|
+
*/
|
|
34
|
+
get error(): string;
|
|
35
|
+
/**
|
|
36
|
+
* The "previous value" of the input element.
|
|
37
|
+
*/
|
|
38
|
+
get previousValue(): TValue;
|
|
39
|
+
/**
|
|
40
|
+
* The serialize settings of the input element.
|
|
41
|
+
*/
|
|
42
|
+
get serializeSettings(): ControlSerializeSettings;
|
|
43
|
+
/**
|
|
44
|
+
* The "touched" state of the input element.
|
|
45
|
+
*/
|
|
46
|
+
get touched(): boolean;
|
|
47
|
+
/**
|
|
48
|
+
* The current value of the input element.
|
|
49
|
+
*/
|
|
50
|
+
get value(): TValue;
|
|
51
|
+
/**
|
|
52
|
+
* The registered callback function called when a change or input event occurs on the input
|
|
53
|
+
* element.
|
|
54
|
+
*/
|
|
55
|
+
onChange: (_: TValue) => void;
|
|
56
|
+
/**
|
|
57
|
+
* Registers a function called when the control error changes.
|
|
58
|
+
*/
|
|
59
|
+
onErrorChange: (error: string) => void;
|
|
60
|
+
/**
|
|
61
|
+
* The registered callback function called when a blur event occurs on the input element.
|
|
62
|
+
*/
|
|
63
|
+
onTouched: (_isTouched: boolean) => void;
|
|
64
|
+
/**
|
|
65
|
+
* Registers a function called when the control value changes.
|
|
66
|
+
* @param {(_value:ValidControlValue)=>void} fn
|
|
67
|
+
* @returns void
|
|
68
|
+
*/
|
|
69
|
+
registerOnChange(fn: (_value: TValue) => void): void;
|
|
70
|
+
/**
|
|
71
|
+
* Registers a function called when the control error changes.
|
|
72
|
+
* @param {(error:string)=>void} fn
|
|
73
|
+
*/
|
|
74
|
+
registerOnErrorChange(fn: (error: string) => void): void;
|
|
75
|
+
/**
|
|
76
|
+
* Registers a function called when the control is touched.
|
|
77
|
+
* @param {(isTouched:boolean)=>void} fn
|
|
78
|
+
* @returns void
|
|
79
|
+
*/
|
|
80
|
+
registerOnTouched(fn: (isTouched: boolean) => void): void;
|
|
81
|
+
/**
|
|
82
|
+
* Sets the "touched" state of the input element.
|
|
83
|
+
* @param {boolean} isTouched
|
|
84
|
+
*/
|
|
85
|
+
setTouched(isTouched: boolean): void;
|
|
86
|
+
/**
|
|
87
|
+
* Sets the "value" property on the input element.
|
|
88
|
+
* @param {ValidControlValue} value
|
|
89
|
+
* @returns void
|
|
90
|
+
*/
|
|
91
|
+
setValue(value: TValue, options?: SetOptions): void;
|
|
92
|
+
/**
|
|
93
|
+
* Set the error message for the control.
|
|
94
|
+
* @param {string} error
|
|
95
|
+
*/
|
|
96
|
+
protected setError(error: string): void;
|
|
97
|
+
/**
|
|
98
|
+
* Sets the "previous value" of the input element.
|
|
99
|
+
* @param {ValidControlValue} value
|
|
100
|
+
* @returns void
|
|
101
|
+
*/
|
|
102
|
+
protected setPreviousValue(value: TValue): void;
|
|
103
|
+
/**
|
|
104
|
+
* Sets the serialize settings of the input element.
|
|
105
|
+
* @param {ControlSerializeSettings} settings
|
|
106
|
+
*/
|
|
107
|
+
protected setSerializeSettings(settings: ControlSerializeSettings): void;
|
|
108
|
+
}
|
|
109
|
+
//# sourceMappingURL=ControlValueAccessorBase.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ControlValueAccessorBase.d.ts","sourceRoot":"","sources":["../../../../src/control/accessor/ControlValueAccessorBase.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAA;AAChD,OAAO,EAAE,WAAW,EAAE,MAAM,mCAAmC,CAAA;AAE/D,OAAO,KAAK,EACV,wBAAwB,EAAE,oBAAoB,EAAE,UAAU,EAC3D,MAAM,2BAA2B,CAAA;AAClC,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAA;AAE/D,MAAM,MAAM,8BAA8B,GAAG;IAC3C,aAAa,CAAC,EAAE,OAAO,CAAA;CACxB,CAAA;AAED,eAAO,MAAM,iBAAiB,EAAE,UAAmC,CAAA;AAEnE,MAAM,MAAM,8BAA8B,CAAC,MAAM,GAAG,iBAAiB,IAAI;IACvE,YAAY,EAAE;QAAE,KAAK,EAAE,MAAM,CAAA;KAAE,CAAA;IAC/B,YAAY,EAAE;QAAE,OAAO,EAAE,OAAO,CAAA;KAAE,CAAA;IAClC,YAAY,EAAE;QAAE,KAAK,EAAE,MAAM,CAAA;KAAE,CAAA;CAChC,CAAA;AAED;;GAEG;AACH,qBAAa,wBAAwB,CACnC,MAAM,GAAG,iBAAiB,EAC1B,UAAU,SAAS,8BAA8B,CAAC,MAAM,CAAC,GAAG,8BAA8B,CAAC,MAAM,CAAC,CAElG,SAAQ,WAAW,CAAC,UAAU,EAAE,UAAU,CAC1C,YAAW,oBAAoB,CAAC,MAAM,CAAC;IAW3B,OAAO,CAAC,MAAM;IAV1B,OAAO,CAAC,MAAM,CAAa;IAE3B,OAAO,CAAC,cAAc,CAAsB;IAE5C,OAAO,CAAC,kBAAkB,CAAsE;IAEhG,OAAO,CAAC,QAAQ,CAAiB;IAEjC,OAAO,CAAC,MAAM,CAAsB;gBAEhB,MAAM,EAAE,8BAA8B;IAI1D;;OAEG;IACH,IAAI,KAAK,WAER;IAED;;OAEG;IACH,IAAI,aAAa,WAEhB;IAED;;OAEG;IACH,IAAI,iBAAiB,6BAEpB;IAED;;OAEG;IACH,IAAI,OAAO,YAEV;IAED;;OAEG;IACH,IAAI,KAAK,WAER;IAED;;;OAGG;IACH,QAAQ,GAAI,GAAG,MAAM,UAAO;IAE5B;;OAEG;IACH,aAAa,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,CAAW;IAEjD;;OAEG;IACH,SAAS,GAAI,YAAY,OAAO,UAAO;IAEvC;;;;OAIG;IACH,gBAAgB,CAAC,EAAE,EAAE,CAAC,MAAM,EAAE,MAAM,KAAK,IAAI,GAAG,IAAI;IAIpD;;;OAGG;IACH,qBAAqB,CAAC,EAAE,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI;IAIjD;;;;OAIG;IACH,iBAAiB,CAAC,EAAE,EAAE,CAAC,SAAS,EAAE,OAAO,KAAK,IAAI,GAAG,IAAI;IAIzD;;;OAGG;IACH,UAAU,CAAC,SAAS,EAAE,OAAO;IAW7B;;;;OAIG;IACH,QAAQ,CAAC,KAAK,EAAE,MAAM,EAAE,OAAO,aAAoB,GAAG,IAAI;IAe1D;;;OAGG;IACH,SAAS,CAAC,QAAQ,CAAC,KAAK,EAAE,MAAM;IAWhC;;;;OAIG;IACH,SAAS,CAAC,gBAAgB,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI;IAI/C;;;OAGG;IACH,SAAS,CAAC,oBAAoB,CAAC,QAAQ,EAAE,wBAAwB;CAGlE"}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Reports that a control is valid, meaning that no errors exist in the input value.
|
|
3
|
+
*/
|
|
4
|
+
export declare const VALID: "VALID";
|
|
5
|
+
/**
|
|
6
|
+
* Reports that a control is invalid, meaning that an error exists in the input value.
|
|
7
|
+
*/
|
|
8
|
+
export declare const INVALID: "INVALID";
|
|
9
|
+
/**
|
|
10
|
+
* Reports that a control is pending, meaning that async validation is occurring and
|
|
11
|
+
* errors are not yet available for the input value.
|
|
12
|
+
*/
|
|
13
|
+
export declare const PENDING: "PENDING";
|
|
14
|
+
/**
|
|
15
|
+
* Reports that a control is disabled, meaning that the control is exempt from ancestor
|
|
16
|
+
* calculations of validity or value.
|
|
17
|
+
*/
|
|
18
|
+
export declare const DISABLED: "DISABLED";
|
|
19
|
+
/**
|
|
20
|
+
* A control can have several different statuses. Each
|
|
21
|
+
* possible status is returned as a string literal.
|
|
22
|
+
*
|
|
23
|
+
* * **VALID**: Reports that a control is valid, meaning that no errors exist in the input
|
|
24
|
+
* value.
|
|
25
|
+
* * **INVALID**: Reports that a control is invalid, meaning that an error exists in the input
|
|
26
|
+
* value.
|
|
27
|
+
* * **PENDING**: Reports that a control is pending, meaning that async validation is
|
|
28
|
+
* occurring and errors are not yet available for the input value.
|
|
29
|
+
* * **DISABLED**: Reports that a control is
|
|
30
|
+
* disabled, meaning that the control is exempt from ancestor calculations of validity or value.
|
|
31
|
+
*/
|
|
32
|
+
export type FormControlStatus = typeof VALID | typeof INVALID | typeof PENDING | typeof DISABLED;
|
|
33
|
+
//# sourceMappingURL=FormControlStatus.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"FormControlStatus.d.ts","sourceRoot":"","sources":["../../../../src/control/accessor/FormControlStatus.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,eAAO,MAAM,KAAK,EAAG,OAAgB,CAAA;AAErC;;GAEG;AACH,eAAO,MAAM,OAAO,EAAG,SAAkB,CAAA;AAEzC;;;GAGG;AACH,eAAO,MAAM,OAAO,EAAG,SAAkB,CAAA;AAEzC;;;GAGG;AACH,eAAO,MAAM,QAAQ,EAAG,UAAmB,CAAA;AAE3C;;;;;;;;;;;;GAYG;AACH,MAAM,MAAM,iBAAiB,GAAG,OAAO,KAAK,GAAG,OAAO,OAAO,GAAG,OAAO,OAAO,GAAG,OAAO,QAAQ,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ValidControlValue.d.ts","sourceRoot":"","sources":["../../../../src/control/accessor/ValidControlValue.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,iBAAiB,GAAG,MAAM,GAAG,SAAS,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/control/accessor/index.ts"],"names":[],"mappings":"AAAA,cAAc,2BAA2B,CAAA;AACzC,cAAc,+BAA+B,CAAA;AAC7C,cAAc,wBAAwB,CAAA;AACtC,cAAc,wBAAwB,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/control/index.ts"],"names":[],"mappings":"AAAA,cAAc,sBAAsB,CAAA;AACpC,cAAc,qBAAqB,CAAA;AACnC,cAAc,kBAAkB,CAAA;AAChC,cAAc,sBAAsB,CAAA"}
|
package/dist/browser/index.d.ts
CHANGED
|
@@ -1,218 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
import { BaseParams, EmptyObject } from '@xylabs/object';
|
|
8
|
-
import { BaseEmitter } from '@xyo-network/module-event-emitter';
|
|
9
|
-
import { Promisable } from '@xylabs/promise';
|
|
10
|
-
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
11
|
-
import { ArchivistInstance } from '@xyo-network/archivist-model';
|
|
12
|
-
|
|
13
|
-
type ValidControlValue = string | undefined;
|
|
14
|
-
|
|
15
|
-
interface SetOptions {
|
|
16
|
-
disableEmit?: boolean;
|
|
17
|
-
}
|
|
18
|
-
interface ControlSerializeSettings {
|
|
19
|
-
sensitive?: boolean;
|
|
20
|
-
serializable?: boolean;
|
|
21
|
-
}
|
|
22
|
-
interface ControlValueAccessor<T = ValidControlValue> {
|
|
23
|
-
readonly error: string;
|
|
24
|
-
readonly previousValue: T;
|
|
25
|
-
readonly serializeSettings: ControlSerializeSettings;
|
|
26
|
-
readonly touched: boolean;
|
|
27
|
-
readonly value: T;
|
|
28
|
-
registerOnChange(fn: (value: T) => void): void;
|
|
29
|
-
registerOnErrorChange(fn: (error: string) => void): void;
|
|
30
|
-
registerOnTouched(fn: (isTouched: boolean) => void): void;
|
|
31
|
-
setTouched(isTouched: boolean): void;
|
|
32
|
-
setValue(fieldValue: T, options?: SetOptions): void;
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
type ControlValueAccessorBaseConfig = {
|
|
36
|
-
disableEvents?: boolean;
|
|
37
|
-
};
|
|
38
|
-
declare const DefaultSetOptions: SetOptions;
|
|
39
|
-
type ControlValueAccessorBaseEvents<TValue = ValidControlValue> = {
|
|
40
|
-
errorChanged: {
|
|
41
|
-
error: string;
|
|
42
|
-
};
|
|
43
|
-
touchChanged: {
|
|
44
|
-
touched: boolean;
|
|
45
|
-
};
|
|
46
|
-
valueChanged: {
|
|
47
|
-
value: TValue;
|
|
48
|
-
};
|
|
49
|
-
};
|
|
50
|
-
declare class ControlValueAccessorBase<TValue = ValidControlValue, TEventData extends ControlValueAccessorBaseEvents<TValue> = ControlValueAccessorBaseEvents<TValue>> extends BaseEmitter<BaseParams, TEventData> implements ControlValueAccessor<TValue> {
|
|
51
|
-
private config;
|
|
52
|
-
private _error;
|
|
53
|
-
private _previousValue;
|
|
54
|
-
private _serializeSettings;
|
|
55
|
-
private _touched;
|
|
56
|
-
private _value;
|
|
57
|
-
constructor(config: ControlValueAccessorBaseConfig);
|
|
58
|
-
get error(): string;
|
|
59
|
-
get previousValue(): TValue;
|
|
60
|
-
get serializeSettings(): ControlSerializeSettings;
|
|
61
|
-
get touched(): boolean;
|
|
62
|
-
get value(): TValue;
|
|
63
|
-
onChange: (_: TValue) => void;
|
|
64
|
-
onErrorChange: (error: string) => void;
|
|
65
|
-
onTouched: (_isTouched: boolean) => void;
|
|
66
|
-
registerOnChange(fn: (_value: TValue) => void): void;
|
|
67
|
-
registerOnErrorChange(fn: (error: string) => void): void;
|
|
68
|
-
registerOnTouched(fn: (isTouched: boolean) => void): void;
|
|
69
|
-
setTouched(isTouched: boolean): void;
|
|
70
|
-
setValue(value: TValue, options?: SetOptions): void;
|
|
71
|
-
protected setError(error: string): void;
|
|
72
|
-
protected setPreviousValue(value: TValue): void;
|
|
73
|
-
protected setSerializeSettings(settings: ControlSerializeSettings): void;
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
declare const VALID: "VALID";
|
|
77
|
-
declare const INVALID: "INVALID";
|
|
78
|
-
declare const PENDING: "PENDING";
|
|
79
|
-
declare const DISABLED: "DISABLED";
|
|
80
|
-
type FormControlStatus = typeof VALID | typeof INVALID | typeof PENDING | typeof DISABLED;
|
|
81
|
-
|
|
82
|
-
type AbstractControlEvents<TValue> = ControlValueAccessorBaseEvents<TValue> & {
|
|
83
|
-
statusChanged: {
|
|
84
|
-
status: FormControlStatus;
|
|
85
|
-
};
|
|
86
|
-
};
|
|
87
|
-
declare class AbstractControl<TValue extends ValidControlValue = ValidControlValue> extends ControlValueAccessorBase<TValue, AbstractControlEvents<TValue>> {
|
|
88
|
-
private _status;
|
|
89
|
-
constructor();
|
|
90
|
-
get disabled(): boolean;
|
|
91
|
-
get enabled(): boolean;
|
|
92
|
-
get invalid(): boolean;
|
|
93
|
-
get pending(): boolean;
|
|
94
|
-
get rawValue(): TValue;
|
|
95
|
-
get status(): FormControlStatus | undefined;
|
|
96
|
-
get valid(): boolean;
|
|
97
|
-
setErrorAndValidity(error: string, status: FormControlStatus): void;
|
|
98
|
-
setStatus(status: FormControlStatus): void;
|
|
99
|
-
validate(): boolean;
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
type CursorPosition = {
|
|
103
|
-
current: number | undefined;
|
|
104
|
-
previous: number | undefined;
|
|
105
|
-
};
|
|
106
|
-
interface FormControlValidator {
|
|
107
|
-
blurError?: (value: string) => void;
|
|
108
|
-
changeError?: (value: string) => void;
|
|
109
|
-
pattern?: RegExp;
|
|
110
|
-
patternStrict?: RegExp;
|
|
111
|
-
required?: boolean;
|
|
112
|
-
}
|
|
113
|
-
interface FormControlMask {
|
|
114
|
-
cursorPosition: CursorPosition;
|
|
115
|
-
getCursorPosition?: () => number | undefined;
|
|
116
|
-
mask?: (value: string) => string;
|
|
117
|
-
onCursorChange?: (cursor: number | undefined) => void;
|
|
118
|
-
unmask?: (value: string) => string;
|
|
119
|
-
}
|
|
120
|
-
interface FormControl<TProps extends EmptyObject = EmptyObject> extends FormControlValidator, FormControlMask, AbstractControl {
|
|
121
|
-
readonly name?: string;
|
|
122
|
-
props: TProps;
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
declare abstract class FormControlBase<TProps extends EmptyObject = EmptyObject> extends AbstractControl implements FormControl {
|
|
126
|
-
cursorPosition: CursorPosition;
|
|
127
|
-
invalidMessage: string;
|
|
128
|
-
pattern: RegExp;
|
|
129
|
-
patternStrict: RegExp;
|
|
130
|
-
props: TProps;
|
|
131
|
-
required: boolean;
|
|
132
|
-
private _name;
|
|
133
|
-
constructor();
|
|
134
|
-
get name(): string | undefined;
|
|
135
|
-
get rawValue(): ValidControlValue;
|
|
136
|
-
blurError?(value: string): void | undefined;
|
|
137
|
-
changeError?(value: string): void;
|
|
138
|
-
getCursorPosition?(): number | undefined;
|
|
139
|
-
mask?(value: string): string;
|
|
140
|
-
onCursorChange: (cursor: number | undefined) => void;
|
|
141
|
-
setValue(value: string | undefined, setOptions: SetOptions): void;
|
|
142
|
-
unmask?(value: string): string;
|
|
143
|
-
validate(): boolean;
|
|
144
|
-
protected setName(name: string | undefined): void;
|
|
145
|
-
}
|
|
146
|
-
|
|
147
|
-
type ErrorSummary = {
|
|
148
|
-
errorMessage: string;
|
|
149
|
-
invalidFields: string[];
|
|
150
|
-
};
|
|
151
|
-
|
|
152
|
-
interface FormGroupStorage<TValue extends Payload = Payload> {
|
|
153
|
-
clear: () => Promisable<void>;
|
|
154
|
-
get: () => Promisable<TValue | undefined>;
|
|
155
|
-
insert: (state: TValue) => Promisable<void>;
|
|
156
|
-
}
|
|
157
|
-
|
|
158
|
-
declare class ArchivistFormGroupStorage implements FormGroupStorage {
|
|
159
|
-
private archivist;
|
|
160
|
-
constructor(archivist: ArchivistInstance);
|
|
161
|
-
clear(): Promise<void>;
|
|
162
|
-
get(): Promise<_xyo_network_payload_model.WithStorageMeta<_xyo_network_payload_model.WithStorageMeta<Payload>> | undefined>;
|
|
163
|
-
insert(value: Payload): Promise<void>;
|
|
164
|
-
}
|
|
165
|
-
|
|
166
|
-
type PayloadWithTimestamp = Payload<{
|
|
167
|
-
timestamp?: number;
|
|
168
|
-
}>;
|
|
169
|
-
type KeyOfString<T> = keyof T extends string ? keyof T : never;
|
|
170
|
-
type FormGroupErrors<TValue> = Record<KeyOfString<TValue>, string>;
|
|
171
|
-
type FormGroupParams<TStorageValue extends Payload = Payload> = {
|
|
172
|
-
serialize?: boolean;
|
|
173
|
-
storage?: {
|
|
174
|
-
sensitive?: FormGroupStorage<TStorageValue>;
|
|
175
|
-
storage?: FormGroupStorage<TStorageValue>;
|
|
176
|
-
};
|
|
177
|
-
ttlStorage?: number;
|
|
178
|
-
};
|
|
179
|
-
declare class FormGroup<TValue extends PayloadWithTimestamp = PayloadWithTimestamp, TStorageValue extends PayloadWithTimestamp = PayloadWithTimestamp> extends AbstractControl {
|
|
180
|
-
private fgParams?;
|
|
181
|
-
private _controls;
|
|
182
|
-
private serializeListeners;
|
|
183
|
-
private serializedSensitiveState;
|
|
184
|
-
private serializedState;
|
|
185
|
-
constructor(fgParams?: FormGroupParams<TStorageValue> | undefined);
|
|
186
|
-
get errorSummary(): ErrorSummary;
|
|
187
|
-
get errors(): FormGroupErrors<TValue>;
|
|
188
|
-
get nonSensitiveStorage(): FormGroupStorage<TStorageValue> | undefined;
|
|
189
|
-
get sensitiveStorage(): FormGroupStorage<TStorageValue> | undefined;
|
|
190
|
-
get touched(): boolean;
|
|
191
|
-
get valid(): boolean;
|
|
192
|
-
get values(): TValue;
|
|
193
|
-
getControl(name: string): Record<KeyOfString<TValue>, AbstractControl<ValidControlValue>>[KeyOfString<TValue>];
|
|
194
|
-
getSerializedValue(name: string, sensitive?: boolean): Promise<string | undefined>;
|
|
195
|
-
registerControl(name: string, control: AbstractControl): void;
|
|
196
|
-
resetControls(): void;
|
|
197
|
-
resetValues(): void;
|
|
198
|
-
unregisterControl(name: string): void;
|
|
199
|
-
validateFields(requiredFields?: string[] | undefined): void;
|
|
200
|
-
private serializeControlValue;
|
|
201
|
-
private serializeValues;
|
|
202
|
-
private setStateValueFromStorage;
|
|
203
|
-
}
|
|
204
|
-
|
|
205
|
-
interface FormGroupContextWithPayloadState<TValue extends Payload = Payload, TStorageValue extends Payload = Payload> extends ContextExState {
|
|
206
|
-
formGroup?: FormGroup<TValue, TStorageValue>;
|
|
207
|
-
}
|
|
208
|
-
|
|
209
|
-
declare const FormGroupBaseContext: react.Context<FormGroupContextWithPayloadState<_xyo_network_payload_model.Payload, _xyo_network_payload_model.Payload> & _xyo_network_react_shared.ContextExState>;
|
|
210
|
-
|
|
211
|
-
interface FormGroupPayloadProviderProps<TStorage extends Payload = Payload> extends PropsWithChildren {
|
|
212
|
-
params?: FormGroupParams<TStorage>;
|
|
213
|
-
}
|
|
214
|
-
declare const FormGroupPayloadProvider: ({ children, params, ...props }: FormGroupPayloadProviderProps) => react_jsx_runtime.JSX.Element;
|
|
215
|
-
|
|
216
|
-
declare const useFormGroup: (required?: boolean) => Omit<FormGroupContextWithPayloadState<_xyo_network_payload_model.Payload, _xyo_network_payload_model.Payload> & _xyo_network_react_shared.ContextExState, "provided">;
|
|
217
|
-
|
|
218
|
-
export { AbstractControl, type AbstractControlEvents, ArchivistFormGroupStorage, type ControlSerializeSettings, type ControlValueAccessor, ControlValueAccessorBase, type ControlValueAccessorBaseConfig, type ControlValueAccessorBaseEvents, type CursorPosition, DISABLED, DefaultSetOptions, type ErrorSummary, type FormControl, FormControlBase, type FormControlMask, type FormControlStatus, type FormControlValidator, FormGroup, FormGroupBaseContext, type FormGroupContextWithPayloadState, type FormGroupParams, FormGroupPayloadProvider, type FormGroupPayloadProviderProps, type FormGroupStorage, INVALID, type KeyOfString, PENDING, type PayloadWithTimestamp, type SetOptions, VALID, type ValidControlValue, useFormGroup };
|
|
1
|
+
export * from './context/index.ts';
|
|
2
|
+
export * from './control/index.ts';
|
|
3
|
+
export * from './FormGroup.ts';
|
|
4
|
+
export * from './InputError.ts';
|
|
5
|
+
export * from './storage/index.ts';
|
|
6
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,oBAAoB,CAAA;AAClC,cAAc,oBAAoB,CAAA;AAClC,cAAc,gBAAgB,CAAA;AAC9B,cAAc,iBAAiB,CAAA;AAC/B,cAAc,oBAAoB,CAAA"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { ArchivistInstance } from '@xyo-network/archivist-model';
|
|
2
|
+
import type { Payload } from '@xyo-network/payload-model';
|
|
3
|
+
import type { FormGroupStorage } from './FormGroupStorage.ts';
|
|
4
|
+
export declare class ArchivistFormGroupStorage implements FormGroupStorage {
|
|
5
|
+
private archivist;
|
|
6
|
+
constructor(archivist: ArchivistInstance);
|
|
7
|
+
clear(): Promise<void>;
|
|
8
|
+
get(): Promise<import("@xyo-network/payload-model").WithStorageMeta<import("@xyo-network/payload-model").WithStorageMeta<Payload>> | undefined>;
|
|
9
|
+
insert(value: Payload): Promise<void>;
|
|
10
|
+
}
|
|
11
|
+
//# sourceMappingURL=ArchivistFormGroupStorage.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ArchivistFormGroupStorage.d.ts","sourceRoot":"","sources":["../../../src/storage/ArchivistFormGroupStorage.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,8BAA8B,CAAA;AACrE,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,4BAA4B,CAAA;AAEzD,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAA;AAE7D,qBAAa,yBAA0B,YAAW,gBAAgB;IACpD,OAAO,CAAC,SAAS;gBAAT,SAAS,EAAE,iBAAiB;IAE1C,KAAK;IAIL,GAAG;IAKH,MAAM,CAAC,KAAK,EAAE,OAAO;CAG5B"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { Promisable } from '@xylabs/promise';
|
|
2
|
+
import type { Payload } from '@xyo-network/payload-model';
|
|
3
|
+
export interface FormGroupStorage<TValue extends Payload = Payload> {
|
|
4
|
+
clear: () => Promisable<void>;
|
|
5
|
+
get: () => Promisable<TValue | undefined>;
|
|
6
|
+
insert: (state: TValue) => Promisable<void>;
|
|
7
|
+
}
|
|
8
|
+
//# sourceMappingURL=FormGroupStorage.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"FormGroupStorage.d.ts","sourceRoot":"","sources":["../../../src/storage/FormGroupStorage.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAA;AACjD,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,4BAA4B,CAAA;AAEzD,MAAM,WAAW,gBAAgB,CAAC,MAAM,SAAS,OAAO,GAAG,OAAO;IAChE,KAAK,EAAE,MAAM,UAAU,CAAC,IAAI,CAAC,CAAA;IAC7B,GAAG,EAAE,MAAM,UAAU,CAAC,MAAM,GAAG,SAAS,CAAC,CAAA;IACzC,MAAM,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,UAAU,CAAC,IAAI,CAAC,CAAA;CAC5C"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/storage/index.ts"],"names":[],"mappings":"AAAA,cAAc,gCAAgC,CAAA;AAC9C,cAAc,uBAAuB,CAAA"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@xyo-network/react-form-group",
|
|
3
|
-
"version": "4.4.
|
|
3
|
+
"version": "4.4.11",
|
|
4
4
|
"description": "Common React library for all XYO projects that use React",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"xyo",
|
|
@@ -44,25 +44,25 @@
|
|
|
44
44
|
},
|
|
45
45
|
"dependencies": {
|
|
46
46
|
"@mui/icons-material": "^6.4.6",
|
|
47
|
-
"@xylabs/forget": "^4.5.
|
|
48
|
-
"@xylabs/object": "^4.5.
|
|
49
|
-
"@xylabs/promise": "^4.5.
|
|
50
|
-
"@xyo-network/archivist-model": "^3.9.
|
|
51
|
-
"@xyo-network/module-event-emitter": "^3.9.
|
|
52
|
-
"@xyo-network/module-events": "^3.9.
|
|
53
|
-
"@xyo-network/payload-model": "^3.9.
|
|
54
|
-
"@xyo-network/react-shared": "^4.4.
|
|
47
|
+
"@xylabs/forget": "^4.5.6",
|
|
48
|
+
"@xylabs/object": "^4.5.6",
|
|
49
|
+
"@xylabs/promise": "^4.5.6",
|
|
50
|
+
"@xyo-network/archivist-model": "^3.9.25",
|
|
51
|
+
"@xyo-network/module-event-emitter": "^3.9.25",
|
|
52
|
+
"@xyo-network/module-events": "^3.9.25",
|
|
53
|
+
"@xyo-network/payload-model": "^3.9.25",
|
|
54
|
+
"@xyo-network/react-shared": "^4.4.11"
|
|
55
55
|
},
|
|
56
56
|
"devDependencies": {
|
|
57
57
|
"@mui/material": "^6.4.6",
|
|
58
58
|
"@mui/styles": "^6.4.6",
|
|
59
|
-
"@storybook/react": "^8.6.
|
|
60
|
-
"@xylabs/ts-scripts-yarn3": "^5.0.
|
|
61
|
-
"@xylabs/tsconfig-react": "^5.0.
|
|
59
|
+
"@storybook/react": "^8.6.3",
|
|
60
|
+
"@xylabs/ts-scripts-yarn3": "^5.0.39",
|
|
61
|
+
"@xylabs/tsconfig-react": "^5.0.39",
|
|
62
62
|
"react": "^18.3.1",
|
|
63
63
|
"react-dom": "^18.3.1",
|
|
64
|
-
"storybook": "^8.6.
|
|
65
|
-
"typescript": "^5.
|
|
64
|
+
"storybook": "^8.6.3",
|
|
65
|
+
"typescript": "^5.8.2"
|
|
66
66
|
},
|
|
67
67
|
"peerDependencies": {
|
|
68
68
|
"@mui/material": "^6",
|