@xyo-network/react-form-group 6.1.4 → 7.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.
@@ -1,393 +1,6 @@
1
- import * as react from 'react';
2
- import { PropsWithChildren } from 'react';
3
- import * as _xylabs_react_shared from '@xylabs/react-shared';
4
- import { ContextExState } from '@xylabs/react-shared';
5
- import { BaseParams } from '@xylabs/base';
6
- import { ModuleBaseEmitter } from '@xyo-network/module-event-emitter';
7
- import * as _xyo_network_payload_model from '@xyo-network/payload-model';
8
- import { Payload } from '@xyo-network/payload-model';
9
- import { Promisable } from '@xylabs/promise';
10
- import * as react_jsx_runtime from 'react/jsx-runtime';
11
- import { EmptyObject } from '@xylabs/object';
12
- import { ArchivistInstance } from '@xyo-network/archivist-model';
13
-
14
- type ValidControlValue = string | undefined;
15
-
16
- interface SetOptions {
17
- disableEmit?: boolean;
18
- }
19
- interface ControlSerializeSettings {
20
- sensitive?: boolean;
21
- serializable?: boolean;
22
- }
23
- interface ControlValueAccessor<T = ValidControlValue> {
24
- readonly error: string;
25
- readonly previousValue: T;
26
- readonly serializeSettings: ControlSerializeSettings;
27
- readonly touched: boolean;
28
- readonly value: T;
29
- registerOnChange(fn: (value: T) => void): void;
30
- registerOnErrorChange(fn: (error: string) => void): void;
31
- registerOnTouched(fn: (isTouched: boolean) => void): void;
32
- setTouched(isTouched: boolean): void;
33
- setValue(fieldValue: T, options?: SetOptions): void;
34
- }
35
-
36
- type ControlValueAccessorBaseConfig = {
37
- disableEvents?: boolean;
38
- };
39
- declare const DefaultSetOptions: SetOptions;
40
- type ControlValueAccessorBaseEvents<TValue = ValidControlValue> = {
41
- errorChanged: {
42
- error: string;
43
- };
44
- touchChanged: {
45
- touched: boolean;
46
- };
47
- valueChanged: {
48
- value: TValue;
49
- };
50
- };
51
- /**
52
- * The base class for control value accessors interface
53
- */
54
- declare class ControlValueAccessorBase<TValue = ValidControlValue, TEventData extends ControlValueAccessorBaseEvents<TValue> = ControlValueAccessorBaseEvents<TValue>> extends ModuleBaseEmitter<BaseParams, TEventData> implements ControlValueAccessor<TValue> {
55
- private config;
56
- private _error;
57
- private _previousValue;
58
- private _serializeSettings;
59
- private _touched;
60
- private _value;
61
- constructor(config: ControlValueAccessorBaseConfig);
62
- /**
63
- * The error message for the control.
64
- */
65
- get error(): string;
66
- /**
67
- * The "previous value" of the input element.
68
- */
69
- get previousValue(): TValue;
70
- /**
71
- * The serialize settings of the input element.
72
- */
73
- get serializeSettings(): ControlSerializeSettings;
74
- /**
75
- * The "touched" state of the input element.
76
- */
77
- get touched(): boolean;
78
- /**
79
- * The current value of the input element.
80
- */
81
- get value(): TValue;
82
- /**
83
- * The registered callback function called when a change or input event occurs on the input
84
- * element.
85
- */
86
- onChange: (_: TValue) => void;
87
- /**
88
- * Registers a function called when the control error changes.
89
- */
90
- onErrorChange: (error: string) => void;
91
- /**
92
- * The registered callback function called when a blur event occurs on the input element.
93
- */
94
- onTouched: (_isTouched: boolean) => void;
95
- /**
96
- * Registers a function called when the control value changes.
97
- * @param {(_value:ValidControlValue)=>void} fn
98
- * @returns void
99
- */
100
- registerOnChange(fn: (_value: TValue) => void): void;
101
- /**
102
- * Registers a function called when the control error changes.
103
- * @param {(error:string)=>void} fn
104
- */
105
- registerOnErrorChange(fn: (error: string) => void): void;
106
- /**
107
- * Registers a function called when the control is touched.
108
- * @param {(isTouched:boolean)=>void} fn
109
- * @returns void
110
- */
111
- registerOnTouched(fn: (isTouched: boolean) => void): void;
112
- /**
113
- * Sets the "touched" state of the input element.
114
- * @param {boolean} isTouched
115
- */
116
- setTouched(isTouched: boolean): void;
117
- /**
118
- * Sets the "value" property on the input element.
119
- * @param {ValidControlValue} value
120
- * @returns void
121
- */
122
- setValue(value: TValue, options?: SetOptions): void;
123
- /**
124
- * Set the error message for the control.
125
- * @param {string} error
126
- */
127
- protected setError(error: string): void;
128
- /**
129
- * Sets the "previous value" of the input element.
130
- * @param {ValidControlValue} value
131
- * @returns void
132
- */
133
- protected setPreviousValue(value: TValue): void;
134
- /**
135
- * Sets the serialize settings of the input element.
136
- * @param {ControlSerializeSettings} settings
137
- */
138
- protected setSerializeSettings(settings: ControlSerializeSettings): void;
139
- }
140
-
141
- /**
142
- * Reports that a control is valid, meaning that no errors exist in the input value.
143
- */
144
- declare const VALID: "VALID";
145
- /**
146
- * Reports that a control is invalid, meaning that an error exists in the input value.
147
- */
148
- declare const INVALID: "INVALID";
149
- /**
150
- * Reports that a control is pending, meaning that async validation is occurring and
151
- * errors are not yet available for the input value.
152
- */
153
- declare const PENDING: "PENDING";
154
- /**
155
- * Reports that a control is disabled, meaning that the control is exempt from ancestor
156
- * calculations of validity or value.
157
- */
158
- declare const DISABLED: "DISABLED";
159
- /**
160
- * A control can have several different statuses. Each
161
- * possible status is returned as a string literal.
162
- *
163
- * * **VALID**: Reports that a control is valid, meaning that no errors exist in the input
164
- * value.
165
- * * **INVALID**: Reports that a control is invalid, meaning that an error exists in the input
166
- * value.
167
- * * **PENDING**: Reports that a control is pending, meaning that async validation is
168
- * occurring and errors are not yet available for the input value.
169
- * * **DISABLED**: Reports that a control is
170
- * disabled, meaning that the control is exempt from ancestor calculations of validity or value.
171
- */
172
- type FormControlStatus = typeof VALID | typeof INVALID | typeof PENDING | typeof DISABLED;
173
-
174
- type AbstractControlEvents<TValue> = ControlValueAccessorBaseEvents<TValue> & {
175
- statusChanged: {
176
- status: FormControlStatus;
177
- };
178
- };
179
- /**
180
- * This is the base class for `Control` classes (i.e. FormControl),
181
- *
182
- * It provides some of the shared behavior that all controls and groups of controls have, like
183
- * running validators, calculating status, and resetting state. It also defines the properties
184
- * that are shared between all sub-classes, like `value`, `valid`, and `dirty`. It shouldn't be
185
- * instantiated directly.
186
- *
187
- * NOTE: Heavily borrowed from Angular's AbstractControl:
188
- * https://github.com/angular/angular/blob/5dcdbfcba934a930468aec140a7183b034466bdf/packages/forms/src/model/abstract_model.ts
189
- */
190
- declare class AbstractControl<TValue extends ValidControlValue = ValidControlValue> extends ControlValueAccessorBase<TValue, AbstractControlEvents<TValue>> {
191
- private _status;
192
- constructor();
193
- /**
194
- * A control is `disabled` when its `status` is `DISABLED`.
195
- *
196
- * Disabled controls are exempt from validation checks and
197
- * are not included in the aggregate value of their ancestor
198
- * controls.
199
- *
200
- * @returns True if the control is disabled, false otherwise.
201
- */
202
- /** @deprecated - disabled functionality not implemented */
203
- get disabled(): boolean;
204
- /**
205
- * A control is `enabled` as long as its `status` is not `DISABLED`.
206
- *
207
- * @returns True if the control has any status other than 'DISABLED',
208
- * false if the status is 'DISABLED'.
209
- */
210
- get enabled(): boolean;
211
- /**
212
- * A control is `invalid` when its `status` is `INVALID`.
213
-
214
- *
215
- * @returns True if this control has failed one or more of its validation checks,
216
- * false otherwise.
217
- */
218
- get invalid(): boolean;
219
- /**
220
- * A control is `pending` when its `status` is `PENDING`.
221
- *
222
- * @returns True if this control is in the process of conducting a validation check,
223
- * false otherwise.
224
- */
225
- get pending(): boolean;
226
- /**
227
- * The raw value of the control.
228
- */
229
- get rawValue(): TValue;
230
- /**
231
- * The current status of the control.
232
- */
233
- get status(): FormControlStatus | undefined;
234
- /**
235
- * A control is `valid` when its `status` is `VALID`.
236
- *
237
- * @returns True if the control has passed all of its validation tests,
238
- * false otherwise.
239
- */
240
- get valid(): boolean;
241
- setErrorAndValidity(error: string, status: FormControlStatus): void;
242
- setStatus(status: FormControlStatus): void;
243
- validate(): boolean;
244
- }
245
-
246
- type CursorPosition = {
247
- current: number | undefined;
248
- previous: number | undefined;
249
- };
250
- interface FormControlValidator {
251
- blurError?: (value: string) => void;
252
- changeError?: (value: string) => void;
253
- pattern?: RegExp;
254
- patternStrict?: RegExp;
255
- required?: boolean;
256
- }
257
- interface FormControlMask {
258
- cursorPosition: CursorPosition;
259
- getCursorPosition?: () => number | undefined;
260
- mask?: (value: string) => string;
261
- onCursorChange?: (cursor: number | undefined) => void;
262
- unmask?: (value: string) => string;
263
- }
264
- interface FormControl<TProps extends EmptyObject = EmptyObject> extends FormControlValidator, FormControlMask, AbstractControl {
265
- readonly name?: string;
266
- props: TProps;
267
- }
268
-
269
- /**
270
- * A base class for form controls and their validation.
271
- */
272
- declare abstract class FormControlBase<TProps extends EmptyObject = EmptyObject> extends AbstractControl implements FormControl {
273
- /**
274
- * The current and previous cursor position of the input element.
275
- */
276
- cursorPosition: CursorPosition;
277
- invalidMessage: string;
278
- pattern: RegExp;
279
- patternStrict: RegExp;
280
- props: TProps;
281
- required: boolean;
282
- private _name;
283
- constructor();
284
- get name(): string | undefined;
285
- get rawValue(): ValidControlValue;
286
- blurError?(value: string): void | undefined;
287
- changeError?(value: string): void;
288
- getCursorPosition?(): number | undefined;
289
- mask?(value: string): string;
290
- onCursorChange: (cursor: number | undefined) => void;
291
- setValue(value: string | undefined, setOptions: SetOptions): void;
292
- unmask?(value: string): string;
293
- validate(): boolean;
294
- protected setName(name: string | undefined): void;
295
- }
296
-
297
- type ErrorSummary = {
298
- errorMessage: string;
299
- invalidFields: string[];
300
- };
301
-
302
- interface FormGroupStorage<TValue extends Payload = Payload> {
303
- clear: () => Promisable<void>;
304
- get: () => Promisable<TValue | undefined>;
305
- insert: (state: TValue) => Promisable<void>;
306
- }
307
-
308
- declare class ArchivistFormGroupStorage implements FormGroupStorage {
309
- private archivist;
310
- constructor(archivist: ArchivistInstance);
311
- clear(): Promise<void>;
312
- get(): Promise<_xyo_network_payload_model.WithStorageMeta<_xyo_network_payload_model.WithStorageMeta<Payload>> | undefined>;
313
- insert(value: Payload): Promise<void>;
314
- }
315
-
316
- type PayloadWithTimestamp = Payload<{
317
- timestamp?: number;
318
- }>;
319
- type KeyOfString<T> = keyof T extends string ? keyof T : never;
320
- type FormGroupErrors<TValue> = Record<KeyOfString<TValue>, string>;
321
- type FormGroupParams<TStorageValue extends Payload = Payload> = {
322
- serialize?: boolean;
323
- storage?: {
324
- sensitive?: FormGroupStorage<TStorageValue>;
325
- storage?: FormGroupStorage<TStorageValue>;
326
- };
327
- ttlStorage?: number;
328
- };
329
- /**
330
- * Organize form controls in a group.
331
- *
332
- * NOTE: This is a work in progress and only supports top level controls. Nested controls are not supported.
333
- */
334
- declare class FormGroup<TValue extends PayloadWithTimestamp = PayloadWithTimestamp, TStorageValue extends PayloadWithTimestamp = PayloadWithTimestamp> extends AbstractControl {
335
- private fgParams?;
336
- private _controls;
337
- private serializeListeners;
338
- private serializedSensitiveState;
339
- private serializedState;
340
- constructor(fgParams?: FormGroupParams<TStorageValue> | undefined);
341
- get errorSummary(): ErrorSummary;
342
- get errors(): FormGroupErrors<TValue>;
343
- get nonSensitiveStorage(): FormGroupStorage<TStorageValue> | undefined;
344
- get sensitiveStorage(): FormGroupStorage<TStorageValue> | undefined;
345
- get touched(): boolean;
346
- get valid(): boolean;
347
- get values(): TValue;
348
- getControl(name: string): Record<KeyOfString<TValue>, AbstractControl<ValidControlValue>>[KeyOfString<TValue>];
349
- getSerializedValue(name: string, sensitive?: boolean): Promise<string | undefined>;
350
- registerControl(name: string, control: AbstractControl): void;
351
- resetControls(): void;
352
- resetValues(): void;
353
- unregisterControl(name: string): void;
354
- validateFields(requiredFields?: string[] | undefined): void;
355
- private serializeControlValue;
356
- private serializeValues;
357
- private setStateValueFromStorage;
358
- }
359
-
360
- declare const FormGroupBaseContext: react.Context<({
361
- formGroup?: FormGroup<_xyo_network_payload_model.Payload, _xyo_network_payload_model.Payload> | undefined;
362
- } & {
363
- provided: true;
364
- }) | (_xylabs_react_shared.FixedValues<_xylabs_react_shared.ProvidedContextExState<{
365
- formGroup?: FormGroup<_xyo_network_payload_model.Payload, _xyo_network_payload_model.Payload> | undefined;
366
- }>, never> & {
367
- provided: false;
368
- }) | (_xylabs_react_shared.FixedValues<_xylabs_react_shared.NotProvidedContextExState<{
369
- formGroup?: FormGroup<_xyo_network_payload_model.Payload, _xyo_network_payload_model.Payload> | undefined;
370
- }>, never> & {
371
- provided: false;
372
- })>;
373
-
374
- interface FormGroupPayloadProviderProps<TStorage extends Payload = Payload> extends PropsWithChildren {
375
- params?: FormGroupParams<TStorage>;
376
- }
377
- /**
378
- * Provides a FormGroup to child components.
379
- */
380
- declare const FormGroupPayloadProvider: ({ children, params, ...props }: FormGroupPayloadProviderProps) => react_jsx_runtime.JSX.Element;
381
-
382
- type FormGroupContextWithPayloadState<TValue extends Payload = Payload, TStorageValue extends Payload = Payload> = ContextExState<{
383
- formGroup?: FormGroup<TValue, TStorageValue>;
384
- }>;
385
-
386
- declare const useFormGroup: (required?: boolean) => Omit<{
387
- formGroup?: FormGroup<_xyo_network_payload_model.Payload, _xyo_network_payload_model.Payload> | undefined;
388
- } & {
389
- provided: true;
390
- }, "provided"> | Omit<_xylabs_react_shared.NotProvidedContextExState<FormGroupContextWithPayloadState>, "provided">;
391
-
392
- export { AbstractControl, ArchivistFormGroupStorage, ControlValueAccessorBase, DISABLED, DefaultSetOptions, FormControlBase, FormGroup, FormGroupBaseContext, FormGroupPayloadProvider, INVALID, PENDING, VALID, useFormGroup };
393
- export type { AbstractControlEvents, ControlSerializeSettings, ControlValueAccessor, ControlValueAccessorBaseConfig, ControlValueAccessorBaseEvents, CursorPosition, ErrorSummary, FormControl, FormControlMask, FormControlStatus, FormControlValidator, FormGroupContextWithPayloadState, FormGroupParams, FormGroupPayloadProviderProps, FormGroupStorage, KeyOfString, PayloadWithTimestamp, SetOptions, ValidControlValue };
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
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@xyo-network/react-form-group",
3
- "version": "6.1.4",
3
+ "version": "7.0.0",
4
4
  "description": "Common React library for all XYO projects that use React",
5
5
  "keywords": [
6
6
  "xyo",
@@ -38,26 +38,30 @@
38
38
  },
39
39
  "module": "dist/browser/index.mjs",
40
40
  "types": "dist/browser/index.d.ts",
41
+ "files": [
42
+ "dist",
43
+ "src"
44
+ ],
41
45
  "dependencies": {
42
- "@xylabs/base": "^4.13.23",
43
- "@xylabs/forget": "^4.13.23",
44
- "@xylabs/object": "^4.13.23",
45
- "@xylabs/promise": "^4.13.23",
46
- "@xylabs/react-shared": "^6.3.13",
47
- "@xyo-network/archivist-model": "^4.1.7",
48
- "@xyo-network/module-event-emitter": "^4.1.7",
49
- "@xyo-network/payload-model": "^4.1.7"
46
+ "@xylabs/base": "^5.0.0",
47
+ "@xylabs/forget": "^5.0.0",
48
+ "@xylabs/object": "^5.0.0",
49
+ "@xylabs/promise": "^5.0.0",
50
+ "@xylabs/react-shared": "^7.0.0",
51
+ "@xyo-network/archivist-model": "^5.0.0",
52
+ "@xyo-network/module-event-emitter": "^5.0.0",
53
+ "@xyo-network/payload-model": "^5.0.0"
50
54
  },
51
55
  "devDependencies": {
52
56
  "@mui/icons-material": "^7.2.0",
53
57
  "@mui/material": "^7.2.0",
54
58
  "@storybook/react-vite": "^9.0.18",
55
- "@types/react": "^19.1.8",
56
- "@xylabs/events": "^4.13.23",
57
- "@xylabs/ts-scripts-yarn3": "next",
58
- "@xylabs/tsconfig-react": "next",
59
- "react": "^19.1.0",
60
- "react-dom": "^19.1.0",
59
+ "@types/react": "^19.1.9",
60
+ "@xylabs/events": "^5.0.0",
61
+ "@xylabs/ts-scripts-yarn3": "^7.0.2",
62
+ "@xylabs/tsconfig-react": "^7.0.2",
63
+ "react": "^19.1.1",
64
+ "react-dom": "^19.1.1",
61
65
  "storybook": "^9.0.18",
62
66
  "typescript": "^5.8.3"
63
67
  },
package/typedoc.json DELETED
@@ -1,5 +0,0 @@
1
- {
2
- "$schema": "https://typedoc.org/schema.json",
3
- "entryPoints": ["src/index.ts"],
4
- "tsconfig": "./tsconfig.typedoc.json"
5
- }
package/xy.config.ts DELETED
@@ -1,10 +0,0 @@
1
- import type { XyTsupConfig } from '@xylabs/ts-scripts-yarn3'
2
- const config: XyTsupConfig = {
3
- compile: {
4
- browser: { src: true },
5
- node: {},
6
- neutral: {},
7
- },
8
- }
9
-
10
- export default config