@ng-simplicity/forms-core 1.1.1 → 1.1.3

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/index.d.ts CHANGED
@@ -2,20 +2,28 @@ import * as rxjs from 'rxjs';
2
2
  import { Subject, Subscription, Observable, BehaviorSubject } from 'rxjs';
3
3
  import * as i0 from '@angular/core';
4
4
  import { OnInit, OnDestroy, Signal, Type, InjectionToken, Injector, ViewContainerRef, ChangeDetectorRef } from '@angular/core';
5
- import * as i2 from '@angular/forms';
5
+ import * as _angular_forms from '@angular/forms';
6
6
  import { ValidatorFn, UntypedFormControl, FormGroup, AbstractControl, UntypedFormGroup, UntypedFormArray, FormArray } from '@angular/forms';
7
7
  import * as _ng_simplicity_forms_core from '@ng-simplicity/forms-core';
8
8
  import * as i1 from '@angular/common';
9
9
 
10
+ /** Base class that ties RxJS subscriptions to the component's lifetime. */
10
11
  declare abstract class NgsSubscriber {
11
12
  protected readonly destroy$: Subject<void>;
12
13
  protected subscriptions: Subscription[];
14
+ /** Subscribes to `subscribeTo` until the component is destroyed. */
13
15
  subscribe<T>(subscribeTo: Observable<T>, nextObserver: (value: T) => void): void;
14
16
  ngOnDestroy(): void;
15
17
  static ɵfac: i0.ɵɵFactoryDeclaration<NgsSubscriber, never>;
16
18
  static ɵdir: i0.ɵɵDirectiveDeclaration<NgsSubscriber, never, never, {}, {}, never, never, true, never>;
17
19
  }
18
20
 
21
+ /**
22
+ * Shape for server side validation errors, nested to mirror the form structure.
23
+ *
24
+ * @notImplemented
25
+ * @remarks Reserved for future use: nothing in the library consumes it yet.
26
+ */
19
27
  interface NgsServerSideValidationErrorObjectType {
20
28
  key: string;
21
29
  path: string;
@@ -24,103 +32,319 @@ interface NgsServerSideValidationErrorObjectType {
24
32
  children: NgsServerSideValidationErrorObjectType[];
25
33
  }
26
34
 
35
+ /** Map of validator error keys to user facing messages. */
27
36
  type NgsFormsFormErrorKeyValueMap = {
28
37
  [key: string]: string;
29
38
  };
30
39
 
40
+ /** One option of a radio group or select. */
31
41
  interface NgsFormsFormInputOption {
42
+ /** Value written to the form control when the option is chosen. */
32
43
  id: string;
44
+ /** Text shown to the user. */
33
45
  label: string;
46
+ /** Renders the option but prevents choosing it. */
34
47
  disabled?: boolean;
35
48
  }
36
49
 
50
+ /** Base configuration shared by every form item (inputs, containers and content items). */
37
51
  interface NgsFormsFormItemConfigBase {
52
+ /**
53
+ * Stable identifier for the item. Generated with `uuid` by the `create()` factories when omitted.
54
+ * Component state set with `NgsFormsService.updateComponentState()` can be keyed by this value.
55
+ */
38
56
  uuid?: string;
57
+ /**
58
+ * Static visibility flag. `false` keeps the item out of the form, as if `visible$` had emitted `false`.
59
+ *
60
+ * @remarks Ignored when `visible$` is also set.
61
+ */
39
62
  visible?: boolean;
63
+ /**
64
+ * Stream that controls whether the item is rendered.
65
+ *
66
+ * @remarks When the stream emits `false` the item's component is destroyed and its control is removed from the
67
+ * parent form group, so hidden fields are excluded from the form value and from validation. When it emits `true`
68
+ * the component is created again with a fresh control. Items without `visible$` are always rendered.
69
+ * @example
70
+ * ```ts
71
+ * visible$: this.forms.formValue$.pipe(map((v) => v?.profile?.contactMethod === 'email'))
72
+ * ```
73
+ */
40
74
  visible$?: Observable<boolean>;
75
+ /**
76
+ * Initial component state for this item, read by input components through `commonState()`.
77
+ *
78
+ * @remarks Applied when the component is first created, unless state for this item's `uuid` was already set.
79
+ * It takes precedence over state set by `name` and over global state.
80
+ * @example
81
+ * ```ts
82
+ * initialState: { displayMode: 'summary', showEditToggle: true }
83
+ * ```
84
+ */
41
85
  initialState?: any;
42
86
  }
87
+ /**
88
+ * Configuration for items that render a list of child items without creating a form control of their own
89
+ * (for example sections and columns).
90
+ */
43
91
  interface NgsFormsFormItemContainerConfigBase extends NgsFormsFormItemConfigBase {
92
+ /** The child items to render, in order. */
44
93
  items: Array<NgsFormsFormItem<any>>;
45
94
  }
95
+ /**
96
+ * Configuration for `NgsFormsFormGroupComponent`: a named group of child items backed by an `UntypedFormGroup`.
97
+ */
46
98
  interface NgsFormsFormGroupConfig extends NgsFormsFormItemConfigBaseItemWithNameAndValidators, NgsFormsFormItemContainerConfigBase {
47
99
  }
100
+ /** Base configuration for items that own a form control (inputs, groups and arrays). */
48
101
  interface NgsFormsFormItemConfigBaseItemWithNameAndValidators extends NgsFormsFormItemConfigBase {
102
+ /**
103
+ * Control name inside the parent form group. Becomes the key of this item's value in `NgsFormsService.formValue$`.
104
+ */
49
105
  name: string;
106
+ /**
107
+ * Maps validator error keys (for example `required`, `minlength`, `email`) to the message shown to the user.
108
+ *
109
+ * @remarks Only the first error on the control is displayed. Errors without an entry fall back to
110
+ * `Field is invalid: <errorKey>`. Messages appear once the control is touched or dirty, or after
111
+ * `NgsFormsService.setIsSubmitted(true)`.
112
+ */
50
113
  errorMessageMap?: NgsFormsFormErrorKeyValueMap;
114
+ /**
115
+ * Static disabled flag. `true` disables the item's control (and, for groups and arrays, every control inside).
116
+ *
117
+ * @remarks Ignored when `disabled$` is also set. Disabled controls are left out of `NgsFormsService.formValue$`
118
+ * and skip validation, which is how Angular reactive forms treat them.
119
+ */
51
120
  disabled?: boolean;
121
+ /**
122
+ * Stream that controls the disabled state. Each emission disables (`true`) or enables (`false`) the control.
123
+ *
124
+ * @example
125
+ * ```ts
126
+ * disabled$: this.forms.formValue$.pipe(map((v) => !v?.profile?.hasCompany))
127
+ * ```
128
+ */
52
129
  disabled$?: Observable<boolean>;
130
+ /**
131
+ * Angular validators applied to the item's control. Takes precedence over `validators$` when both are set.
132
+ */
53
133
  validators?: Array<ValidatorFn>;
134
+ /**
135
+ * Stream of validator arrays. Each emission replaces the control's validators, which lets rules depend on other
136
+ * values in the form. Ignored when `validators` is also set.
137
+ *
138
+ * @remarks The control's validity is recalculated on its next value change, so call `updateValueAndValidity()`
139
+ * yourself if you need the new rules to apply immediately.
140
+ */
54
141
  validators$?: Observable<Array<ValidatorFn>>;
55
142
  }
143
+ /** Base configuration for a labelled input control. */
56
144
  interface NgsFormsFormItemConfigBaseInput extends NgsFormsFormItemConfigBaseItemWithNameAndValidators {
145
+ /**
146
+ * Element id for the input. When omitted the component generates a unique one.
147
+ *
148
+ * @remarks Must be unique on the page, so avoid it inside form array rows.
149
+ */
57
150
  id?: string;
151
+ /** Label text shown next to or above the control. */
58
152
  label: string;
153
+ /**
154
+ * Initial value of the control. Applied when the control is created, including when a `visible$` item is shown
155
+ * again.
156
+ */
59
157
  value?: unknown;
60
158
  }
159
+ /** Base configuration for single line text inputs. */
61
160
  interface NgsFormsFormItemConfigBaseTextInput extends NgsFormsFormItemConfigBaseInput {
161
+ /** Placeholder text shown while the input is empty. */
62
162
  placeholder?: string;
163
+ /**
164
+ * The HTML input type.
165
+ * @defaultValue 'text'
166
+ */
63
167
  type?: 'text' | 'email' | 'password';
64
168
  }
169
+ /**
170
+ * Base configuration for inputs that choose from a list of options (radio groups and selects).
171
+ */
65
172
  interface NgsFormsFormItemConfigBaseInputWithOptions extends NgsFormsFormItemConfigBaseInput {
173
+ /** Static list of options. Used as the initial value when `options$` is also set. */
66
174
  options?: Array<NgsFormsFormInputOption>;
175
+ /**
176
+ * Stream of options. Each emission replaces the rendered options, which makes cascading selects and
177
+ * server-loaded option lists possible.
178
+ */
67
179
  options$?: Observable<Array<NgsFormsFormInputOption>>;
68
180
  }
69
181
 
182
+ /**
183
+ * A node in the form tree: which registered component to render (`type`) and the configuration to give it.
184
+ *
185
+ * @remarks You rarely build these by hand. Every built-in component has a static `create(config)` factory that
186
+ * returns one with the right `type` and a generated `uuid`.
187
+ */
70
188
  interface NgsFormsFormItem<T extends NgsFormsFormItemConfigBase> {
189
+ /** Unique identifier of the node. */
71
190
  uuid?: string;
191
+ /**
192
+ * Registry key of the component that renders this item, for example `input-text` or `form-group`.
193
+ */
72
194
  type: string;
195
+ /** The configuration handed to the component through the `NGS_FORMS_ITEM_DATA` token. */
73
196
  config: T;
74
197
  }
75
198
 
199
+ /**
200
+ * State that components read through `commonState()`. Set it with `globalState` / `initialState` in the config, or
201
+ * at runtime with `NgsFormsService.updateGlobalState()` and `updateComponentState()`.
202
+ *
203
+ * @remarks The built-in theme components do not read these yet. They are a contract for your own components.
204
+ */
76
205
  interface NgsFormsCommonComponentState {
206
+ /**
207
+ * `input` shows the editable control. `summary` shows a compact, read-only display of the current value, for
208
+ * example to save space on small screens.
209
+ */
77
210
  displayMode?: 'input' | 'summary';
211
+ /** Whether to show a control that lets the user switch between `summary` and `input`. */
78
212
  showEditToggle?: boolean;
79
213
  }
80
214
 
81
215
  interface NgsFormsGlobalFormState extends NgsFormsCommonComponentState {
82
216
  }
83
217
 
218
+ /**
219
+ * The top level configuration passed to `NgsFormsService.setFormConfig()`.
220
+ *
221
+ * @example
222
+ * ```ts
223
+ * const config: NgsFormsFormConfig = {
224
+ * inputUpdateDebounce: 0,
225
+ * globalState: {},
226
+ * root: NgsFormsFormGroupComponent.create({ name: 'profile', items: [ ... ] }),
227
+ * };
228
+ * ```
229
+ */
84
230
  interface NgsFormsFormConfig<T = NgsFormsFormItem<any>> {
231
+ /**
232
+ * Debounce, in milliseconds, for input value updates.
233
+ *
234
+ * @notImplemented
235
+ * @remarks Reserved for future use: values currently update on every change.
236
+ */
85
237
  inputUpdateDebounce: number;
238
+ /**
239
+ * Initial state shared by every component in the form. Applied each time `setFormConfig()` is called; change it
240
+ * later with `NgsFormsService.updateGlobalState()`.
241
+ */
86
242
  globalState: NgsFormsGlobalFormState;
243
+ /**
244
+ * The root item, usually an `NgsFormsFormGroupComponent`, whose form group backs the whole form.
245
+ */
87
246
  root: T;
88
- initialState?: any;
247
+ /**
248
+ * Initial state for individual components, keyed by item `uuid` or control `name`.
249
+ *
250
+ * @remarks Applied each time `setFormConfig()` is called, together with `globalState`. Same as calling
251
+ * `NgsFormsService.updateComponentState(key, state)` for each entry before the form renders.
252
+ * @example
253
+ * ```ts
254
+ * initialState: { email: { displayMode: 'input' } }
255
+ * ```
256
+ */
257
+ initialState?: {
258
+ [componentKey: string]: NgsFormsCommonComponentState & {
259
+ [key: string]: any;
260
+ };
261
+ };
89
262
  }
90
263
 
264
+ /**
265
+ * Root base class for every form item component. Reads the item's configuration from `NGS_FORMS_ITEM_DATA`.
266
+ *
267
+ * @remarks Extend it for components that do not own a form control, such as static content or buttons. Declare a
268
+ * `static key` and a `static create(config)` factory so the component can be registered and used in configs.
269
+ */
91
270
  declare abstract class NgsFormsBaseClassFormComponent<T extends NgsFormsFormItemConfigBase> extends NgsSubscriber {
271
+ /** Registry key the component is registered under. */
92
272
  static key: string;
273
+ /**
274
+ * Element id for this component, handy for `id` and `for` attributes. The config's `id` when it sets one,
275
+ * otherwise a generated unique id.
276
+ */
93
277
  id: string;
278
+ /** The item's configuration. */
94
279
  protected config: T;
280
+ /** The full form item: `uuid`, `type` and `config`. */
95
281
  protected readonly itemData: NgsFormsFormItem<T>;
96
282
  constructor();
97
283
  static ɵfac: i0.ɵɵFactoryDeclaration<NgsFormsBaseClassFormComponent<any>, never>;
98
284
  static ɵdir: i0.ɵɵDirectiveDeclaration<NgsFormsBaseClassFormComponent<any>, never, never, {}, {}, never, never, true, never>;
99
285
  }
100
286
 
287
+ /**
288
+ * Base class for items that own a form control. Creates the control (seeded with `value` when the config has one),
289
+ * applies `validators` / `validators$` and `disabled` / `disabled$`, registers it with the parent group under
290
+ * `config.name` and keeps `errorMessage` up to date.
291
+ */
101
292
  declare class NgsFormsFormItemWithVisibleAndValidatorsBase<T extends NgsFormsFormItemConfigBaseItemWithNameAndValidators> extends NgsFormsBaseClassFormComponent<T> implements OnInit, OnDestroy {
293
+ /** The item's form control. Bind it with `[formControl]`. */
102
294
  control: UntypedFormControl | undefined;
295
+ /**
296
+ * Message for the control's first error, taken from `errorMessageMap`. Empty while the control is valid, or
297
+ * before it is touched, dirty or submitted.
298
+ */
103
299
  errorMessage: string;
104
300
  private formAddRemoveFns;
105
301
  private privateService;
106
302
  private changeDetectorRef;
303
+ /** Whether the form has been marked as submitted with `NgsFormsService.setIsSubmitted()`. */
107
304
  readonly submitted: Signal<boolean>;
305
+ /** The latest value of `disabled` / `disabled$`, or `undefined` when the config sets neither. */
306
+ private disabledFromConfig;
108
307
  ngOnInit(): void;
109
308
  private updateErrorMessage;
110
309
  ngOnDestroy(): void;
111
310
  private bindValidators;
311
+ private bindDisabled;
312
+ private applyDisabled;
112
313
  static ɵfac: i0.ɵɵFactoryDeclaration<NgsFormsFormItemWithVisibleAndValidatorsBase<any>, never>;
113
314
  static ɵdir: i0.ɵɵDirectiveDeclaration<NgsFormsFormItemWithVisibleAndValidatorsBase<any>, never, never, {}, {}, never, never, true, never>;
114
315
  }
115
316
 
317
+ /**
318
+ * Maps registry keys (the `type` of an `NgsFormsFormItem`) to the Angular components that render them.
319
+ *
320
+ * @remarks The service is provided in the `platform` injector, so there is one registry per page. Registering a
321
+ * key again replaces the previous component, which is how a theme package or your own component can override a
322
+ * built-in one. Register components before the form renders, typically in the constructor of the component that
323
+ * hosts `<ngs-form>`.
324
+ * @example
325
+ * ```ts
326
+ * constructor(registry: NgsFormsComponentRegistryService) {
327
+ * NgsFormsBootstrapModule.registerAllBootStrapComponents(registry);
328
+ * registry.register(MyRatingComponent.key, MyRatingComponent);
329
+ * }
330
+ * ```
331
+ */
116
332
  declare class NgsFormsComponentRegistryService {
117
333
  private readonly itemComponentRegistry;
334
+ /** Returns the component registered for `key`, or `undefined` when nothing is registered. */
118
335
  getComponentTypeForKey(key: string): Type<unknown> | undefined;
336
+ /** Registers `component` under `key`, replacing any component already registered for it. */
119
337
  register(key: string, component: Type<unknown>): void;
120
338
  static ɵfac: i0.ɵɵFactoryDeclaration<NgsFormsComponentRegistryService, never>;
121
339
  static ɵprov: i0.ɵɵInjectableDeclaration<NgsFormsComponentRegistryService>;
122
340
  }
123
341
 
342
+ /**
343
+ * Per form state holder that connects `<ngs-form>`, its items and `NgsFormsService`.
344
+ *
345
+ * @remarks Provided by `NgsFormComponent`. Application code should use `NgsFormsService` instead; this service is
346
+ * exported for authors of custom components and may change between minor versions.
347
+ */
124
348
  declare class NgsFormsInternalService {
125
349
  formGroup$: BehaviorSubject<FormGroup<any>>;
126
350
  formConfig$: BehaviorSubject<NgsFormsFormConfig<NgsFormsFormItem<any>> | undefined>;
@@ -132,69 +356,167 @@ declare class NgsFormsInternalService {
132
356
  checkIsValid(): boolean;
133
357
  setFormData(formConfig: NgsFormsFormConfig): void;
134
358
  private mergeState;
359
+ /** Sets a component's state from its config's `initialState`, unless state for `uuid` already exists. */
360
+ seedComponentState(uuid: string, initialState: any): void;
135
361
  updateGlobalState(state: NgsFormsGlobalFormState): void;
136
362
  updateComponentState(componentKey: string, state: any): void;
137
- subscribeToState(uuid: string, name?: string): rxjs.Observable<any>;
363
+ /**
364
+ * Merged state for one component: its own (by `uuid`), then by `name`, then global.
365
+ * `initialState` seeds the component's own state unless state for `uuid` already exists.
366
+ */
367
+ subscribeToState(uuid: string, name?: string, initialState?: any): rxjs.Observable<any>;
138
368
  static ɵfac: i0.ɵɵFactoryDeclaration<NgsFormsInternalService, never>;
139
369
  static ɵprov: i0.ɵɵInjectableDeclaration<NgsFormsInternalService>;
140
370
  }
141
371
 
372
+ /**
373
+ * The public API of a form. Provide it on the component that hosts `<ngs-form>` so each form gets its own instance.
374
+ *
375
+ * @example
376
+ * ```ts
377
+ * @Component({
378
+ * selector: 'app-profile',
379
+ * imports: [NgsFormComponent],
380
+ * providers: [NgsFormsService],
381
+ * template: `<ngs-form />`,
382
+ * })
383
+ * export class ProfileComponent {
384
+ * private readonly forms = inject(NgsFormsService);
385
+ * readonly value = toSignal(this.forms.formValue$);
386
+ * }
387
+ * ```
388
+ */
142
389
  declare class NgsFormsService implements OnDestroy {
390
+ /**
391
+ * @internal
392
+ */
143
393
  attempt: number;
394
+ /**
395
+ * Emits the root form group's value every time it changes. Combine with `toSignal()` to read it in a template.
396
+ *
397
+ * @remarks The value is keyed by the root group's `name`, for example `{ profile: { firstName: 'Ada' } }`.
398
+ */
144
399
  formValue$: BehaviorSubject<any>;
400
+ /** The latest value emitted by `formValue$`. */
145
401
  formValue: any;
146
402
  private internalFormService;
147
403
  private formGroupSubscriptions;
148
404
  private formGroup;
405
+ /** `true` once the user has changed any control in the form. */
149
406
  get dirty(): boolean;
407
+ /** `true` when every rendered control passes its validators. Hidden items are not validated. */
150
408
  get isValid(): boolean;
409
+ /** `true` once `<ngs-form>` has connected to this service. */
151
410
  get internalServiceIsSet(): boolean;
411
+ /**
412
+ * Renders a form from `formConfig`, replacing any form that is already shown and resetting the submitted state.
413
+ *
414
+ * @remarks It is safe to call before `<ngs-form>` has initialised (for example in `ngOnInit`): the call is retried
415
+ * every 25 ms for about half a second until the form component is available.
416
+ */
152
417
  setFormConfig(formConfig: NgsFormsFormConfig): void;
418
+ /**
419
+ * @internal
420
+ */
153
421
  setInternalService(internalFormsService: NgsFormsInternalService): void;
422
+ /**
423
+ * Marks the form as submitted (or not). While submitted, every invalid control shows its error message even if
424
+ * the user never touched it.
425
+ */
154
426
  setIsSubmitted(isSubmitted: boolean): void;
155
427
  private bindFormGroup;
428
+ /**
429
+ * Merges `state` into the state of one component, identified by its `uuid` or control `name`.
430
+ * Components read the merged result through `commonState`.
431
+ */
156
432
  updateComponentState(componentKey: string, state: any): void;
433
+ /** Merges `state` into the state shared by every component in the form. */
157
434
  updateGlobalState(state: any): void;
158
435
  ngOnDestroy(): void;
436
+ /**
437
+ * Patches values into the form, using the same shape as `formValue$` (including the root group name).
438
+ *
439
+ * @remarks Only controls that are currently rendered receive values. Patch again after a conditional item becomes
440
+ * visible, and make sure a form array has enough rows (see `initialItemCount`) before patching array values.
441
+ */
159
442
  patchValue(entityData: any): void;
160
443
  static ɵfac: i0.ɵɵFactoryDeclaration<NgsFormsService, never>;
161
444
  static ɵprov: i0.ɵɵInjectableDeclaration<NgsFormsService>;
162
445
  }
163
446
 
447
+ /**
448
+ * Base class for input components. Adds access to the form's `NgsFormsService` and the merged component state.
449
+ *
450
+ * @remarks This is the class to extend when you build your own input. See the Custom components guide.
451
+ */
164
452
  declare abstract class NgsFormsBaseClassFormInputComponent<T extends NgsFormsFormItemConfigBaseInput> extends NgsFormsFormItemWithVisibleAndValidatorsBase<T> {
453
+ /** The `NgsFormsService` of the form this input belongs to. */
165
454
  readonly myFormService: NgsFormsService;
166
455
  private readonly internalService;
456
+ /** Merged state for this component: its own state, then state by name, then global state. */
167
457
  readonly commonState: Signal<NgsFormsCommonComponentState>;
168
- toggleDisplayMode(setTo: 'summary' | 'input'): void;
458
+ /**
459
+ * Switches this component between `input` and `summary` display by updating its own state.
460
+ * With no argument it flips the current mode.
461
+ */
462
+ toggleDisplayMode(setTo?: 'summary' | 'input'): void;
169
463
  static ɵfac: i0.ɵɵFactoryDeclaration<NgsFormsBaseClassFormInputComponent<any>, never>;
170
464
  static ɵdir: i0.ɵɵDirectiveDeclaration<NgsFormsBaseClassFormInputComponent<any>, never, never, {}, {}, never, never, true, never>;
171
465
  }
172
466
 
467
+ /** Base class for container items that render `config.items` without owning a form control. */
173
468
  declare class NgsFormsBaseClassItemsContainerBase<T extends NgsFormsFormItemContainerConfigBase> extends NgsFormsBaseClassFormComponent<T> implements OnDestroy {
174
469
  static ɵfac: i0.ɵɵFactoryDeclaration<NgsFormsBaseClassItemsContainerBase<any>, never>;
175
470
  static ɵdir: i0.ɵɵDirectiveDeclaration<NgsFormsBaseClassItemsContainerBase<any>, never, never, {}, {}, never, never, true, never>;
176
471
  }
177
472
 
473
+ /**
474
+ * Base class for inputs with options. Exposes `options` as a signal that follows `options$` when given and falls
475
+ * back to the static `options`.
476
+ */
178
477
  declare class NgsFormsBaseClassFormItemInputWithOptionsComponent<T extends NgsFormsFormItemConfigBaseInputWithOptions> extends NgsFormsBaseClassFormInputComponent<T> {
478
+ /** The current options. */
179
479
  options: Signal<Array<NgsFormsFormInputOption>>;
180
480
  static ɵfac: i0.ɵɵFactoryDeclaration<NgsFormsBaseClassFormItemInputWithOptionsComponent<any>, never>;
181
481
  static ɵdir: i0.ɵɵDirectiveDeclaration<NgsFormsBaseClassFormItemInputWithOptionsComponent<any>, never, never, {}, {}, never, never, true, never>;
182
482
  }
183
483
 
484
+ /**
485
+ * Renders the form described by the `NgsFormsFormConfig` given to the nearest `NgsFormsService`.
486
+ *
487
+ * @remarks Place it in the template of the component that provides `NgsFormsService`. It takes no inputs.
488
+ * @example
489
+ * ```html
490
+ * <ngs-form></ngs-form>
491
+ * ```
492
+ */
184
493
  declare class NgsFormComponent {
185
494
  private readonly ngsInternalFormsService;
186
495
  readonly ngsFormsService: NgsFormsService;
187
- readonly formGroup: i0.Signal<i2.FormGroup<any> | undefined>;
496
+ readonly formGroup: i0.Signal<_angular_forms.FormGroup<any> | undefined>;
188
497
  readonly formConfig: i0.Signal<_ng_simplicity_forms_core.NgsFormsFormConfig<_ng_simplicity_forms_core.NgsFormsFormItem<any>> | undefined>;
498
+ /** The root item to render with the form group it belongs to (empty until a config is set). */
499
+ readonly rendered: i0.Signal<{
500
+ group: _angular_forms.FormGroup<any>;
501
+ root: _ng_simplicity_forms_core.NgsFormsFormItem<any>;
502
+ }[]>;
189
503
  constructor();
190
504
  static ɵfac: i0.ɵɵFactoryDeclaration<NgsFormComponent, never>;
191
505
  static ɵcmp: i0.ɵɵComponentDeclaration<NgsFormComponent, "ngs-form", never, {}, {}, never, never, true, never>;
192
506
  }
193
507
 
508
+ /** Injection token for the `NgsFormsFormItem` a component is rendering. */
194
509
  declare const NGS_FORMS_ITEM_DATA: InjectionToken<unknown>;
510
+ /**
511
+ * @internal
512
+ */
195
513
  declare const NGS_FORMS_CONTROL_ADD_REMOVE_FN: InjectionToken<unknown>;
514
+ /** Injection token for the row index when a component is rendered inside a form array list. */
196
515
  declare const NGS_FORMS_ITEM_INDEX: InjectionToken<unknown>;
197
516
  type FormControlAddRemoveFn = (control: AbstractControl, controlName: string) => void;
517
+ /**
518
+ * @internal
519
+ */
198
520
  interface INgsFormsFormControlAddRemove {
199
521
  add: FormControlAddRemoveFn;
200
522
  remove: FormControlAddRemoveFn;
@@ -203,6 +525,9 @@ interface IControlAddRemoveFunctionsBuilder {
203
525
  formGroup: (formGroup: UntypedFormGroup) => INgsFormsFormControlAddRemove;
204
526
  formArray: (formArray: UntypedFormArray) => INgsFormsFormControlAddRemove;
205
527
  }
528
+ /**
529
+ * @internal
530
+ */
206
531
  declare const NgsFormsFormControlAddRemoveFunctions: IControlAddRemoveFunctionsBuilder;
207
532
 
208
533
  /**
@@ -210,11 +535,34 @@ declare const NgsFormsFormControlAddRemoveFunctions: IControlAddRemoveFunctionsB
210
535
  * Returns a new object with properties from source assigned to target
211
536
  * if the properties are undefined or missing on target.
212
537
  */
538
+ /**
539
+ * Returns a copy of `target` with any `undefined` properties filled in from `source`. A dependency free
540
+ * alternative to lodash `defaults`, handy for applying default config values in custom components.
541
+ */
213
542
  declare function ngsDefaults<T extends object, U extends object>(target: T, source: U): T & U;
214
543
 
544
+ /**
545
+ * Function form of a visibility rule.
546
+ *
547
+ * @notImplemented
548
+ * @remarks Reserved for future use. Use `visible$` today.
549
+ */
215
550
  type NgsFormItemVisibilityFn = (params: NgsFormsFunctionParameters) => Observable<boolean> | boolean;
551
+ /**
552
+ * Function form of a validator rule.
553
+ *
554
+ * @notImplemented
555
+ * @remarks Reserved for future use. Use `validators$` today.
556
+ */
216
557
  type NgsFormValidatorArrayBuilderFn = (params: NgsFormsFunctionParameters) => Observable<Array<ValidatorFn>> | Array<ValidatorFn>;
558
+ /**
559
+ * Function form of a disable rule.
560
+ *
561
+ * @notImplemented
562
+ * @remarks Reserved for future use.
563
+ */
217
564
  type NgsFormDisableFn = (params: NgsFormsFunctionParameters) => Observable<boolean> | boolean;
565
+ /** Parameters passed to the function rule types. */
218
566
  interface NgsFormsFunctionParameters {
219
567
  injector: Injector;
220
568
  formGroup: UntypedFormGroup;
@@ -238,10 +586,22 @@ declare class NgsFormItemController extends NgsSubscriber {
238
586
  private detach;
239
587
  }
240
588
 
589
+ /**
590
+ * Structural building block that looks up a form item's component in the registry and renders it.
591
+ *
592
+ * @remarks Use it inside custom container components to render child items:
593
+ * `<ng-container [ngs-form-item]="item" [ngs-form-group]="group"></ng-container>`.
594
+ */
241
595
  declare class NgsFormsFormItemDirective implements OnInit, OnDestroy {
596
+ /** The item to render. */
242
597
  itemData: NgsFormsFormItem<any> | undefined;
598
+ /** Form group that the item's control is added to. */
243
599
  formGroup?: UntypedFormGroup;
600
+ /** Form array that the item's control is added to. */
244
601
  formArray?: UntypedFormArray;
602
+ /**
603
+ * Index of the item inside a form array row, provided to children as `NGS_FORMS_ITEM_INDEX`.
604
+ */
245
605
  index?: number;
246
606
  controller: NgsFormItemController | undefined;
247
607
  private readonly viewContainerRef;
@@ -254,31 +614,71 @@ declare class NgsFormsFormItemDirective implements OnInit, OnDestroy {
254
614
  static ɵdir: i0.ɵɵDirectiveDeclaration<NgsFormsFormItemDirective, "[ngs-form-item]", never, { "itemData": { "alias": "ngs-form-item"; "required": false; }; "formGroup": { "alias": "ngs-form-group"; "required": false; }; "formArray": { "alias": "ngs-form-array"; "required": false; }; "index": { "alias": "ngs-form-index"; "required": false; }; }, {}, never, never, true, never>;
255
615
  }
256
616
 
617
+ /**
618
+ * Renders its items one after another without any wrapper markup. Useful as a grouping node inside a row.
619
+ *
620
+ * @remarks Registry key: `column`. Does not create a form control.
621
+ */
257
622
  declare class NgsFormsColumnComponent extends NgsFormsBaseClassItemsContainerBase<NgsFormsFormItemContainerConfigBase> {
258
623
  static key: string;
624
+ /** Creates a `column` item. */
259
625
  static create(config: NgsFormsFormItemContainerConfigBase): NgsFormsFormItem<NgsFormsFormItemContainerConfigBase>;
260
626
  static ɵfac: i0.ɵɵFactoryDeclaration<NgsFormsColumnComponent, never>;
261
627
  static ɵcmp: i0.ɵɵComponentDeclaration<NgsFormsColumnComponent, "ngs-form-component-column", never, {}, {}, never, never, true, never>;
262
628
  }
263
629
 
630
+ /** Configuration for `NgsFormsRowComponent`. */
264
631
  interface NgsFormItemRowConfig extends NgsFormsFormItemConfigBase {
632
+ /** Class for the element that wraps the whole row. */
265
633
  containerClass?: string;
634
+ /** Class for each item's wrapper, matched by index. */
266
635
  columnClasses?: Array<string> | string;
636
+ /** Class applied to every item's wrapper. Takes precedence over `columnClasses`. */
267
637
  columnClass?: string;
638
+ /** Items to lay out. */
268
639
  items: Array<NgsFormsFormItem<any>>;
269
640
  }
270
641
 
642
+ /**
643
+ * Lays out items side by side. Each item is wrapped in a div whose class comes from `columnClass` (same for every
644
+ * item) or `columnClasses` (one per item), so it works with any CSS grid system.
645
+ *
646
+ * @remarks Registry key: `form-row`. Does not create a form control.
647
+ * @example
648
+ * ```ts
649
+ * NgsFormsRowComponent.create({
650
+ * containerClass: 'row g-3',
651
+ * columnClasses: ['col-md-6', 'col-md-6'],
652
+ * items: [firstName, lastName],
653
+ * })
654
+ * ```
655
+ */
271
656
  declare class NgsFormsRowComponent extends NgsFormsBaseClassFormComponent<NgsFormItemRowConfig> {
272
657
  static key: string;
273
658
  constructor();
274
659
  getIndividualRowDivClass(index: number): string;
660
+ /** Creates a `form-row` item. */
275
661
  static create(config: NgsFormItemRowConfig): NgsFormsFormItem<NgsFormItemRowConfig>;
276
662
  static ɵfac: i0.ɵɵFactoryDeclaration<NgsFormsRowComponent, never>;
277
663
  static ɵcmp: i0.ɵɵComponentDeclaration<NgsFormsRowComponent, "ngs-forms-row-component", never, {}, {}, never, never, true, never>;
278
664
  }
279
665
 
666
+ /**
667
+ * A named group of items backed by an `UntypedFormGroup`. Its value is nested under `name` in the form value.
668
+ *
669
+ * @remarks Registry key: `form-group`. Usually the `root` of a form, and also useful for nesting related fields
670
+ * (an address, for example) or for hiding a whole group with `visible$`.
671
+ * @example
672
+ * ```ts
673
+ * NgsFormsFormGroupComponent.create({
674
+ * name: 'address',
675
+ * items: [addressLine1, city, postcode],
676
+ * })
677
+ * ```
678
+ */
280
679
  declare class NgsFormsFormGroupComponent extends NgsFormsFormItemWithVisibleAndValidatorsBase<NgsFormsFormGroupConfig> implements OnInit {
281
680
  static key: string;
681
+ /** Creates a `form-group` item. */
282
682
  static create(config: NgsFormsFormGroupConfig): NgsFormsFormItem<NgsFormsFormGroupConfig>;
283
683
  get formGroupControl(): UntypedFormGroup;
284
684
  constructor();
@@ -286,83 +686,152 @@ declare class NgsFormsFormGroupComponent extends NgsFormsFormItemWithVisibleAndV
286
686
  static ɵcmp: i0.ɵɵComponentDeclaration<NgsFormsFormGroupComponent, "ngs-forms-form-group", never, {}, {}, never, never, true, never>;
287
687
  }
288
688
 
689
+ /** Configuration for `NgsFormsFormArrayAddItemComponent`. */
289
690
  interface NgsFormItemArrayAddItemConfig extends NgsFormsFormItemConfigBase {
691
+ /**
692
+ * Button label.
693
+ * @defaultValue 'Add Item'
694
+ */
290
695
  buttonText?: string;
696
+ /**
697
+ * Button class.
698
+ * @defaultValue 'btn btn-outline-primary'
699
+ */
291
700
  buttonClass?: string;
701
+ /** Class of an `<i>` icon shown before the label, for example `bi bi-plus`. */
292
702
  buttonIcon?: string;
293
- onAddItem?: () => void;
294
703
  }
295
704
 
705
+ /** Configuration for `NgsFormsFormArrayContainerComponent`. */
296
706
  interface NgsFormItemArrayConfig extends NgsFormsFormItemConfigBaseItemWithNameAndValidators {
707
+ /** Number of rows created when the array first renders. */
297
708
  initialItemCount?: number;
709
+ /** Remove buttons do nothing while the array has this many rows or fewer. */
298
710
  minItems?: number;
711
+ /** Add buttons do nothing once the array has this many rows. */
299
712
  maxItems?: number;
713
+ /** Class for the element that wraps the array's items. */
300
714
  containerClass?: string;
715
+ /**
716
+ * Class for each row.
717
+ *
718
+ * @notImplemented
719
+ * @remarks Reserved for future use. Set `containerClass` on `NgsFormsFormArrayListComponent` to style rows.
720
+ */
301
721
  itemContainerClass?: string;
722
+ /** Items rendered inside the array: typically a list plus an add button. */
302
723
  items: Array<NgsFormsFormItem<any>>;
303
724
  }
304
725
 
726
+ /**
727
+ * A repeatable list of rows backed by an `UntypedFormArray`. Its value is an array under `name`.
728
+ *
729
+ * @remarks Registry key: `form-array`. Put an `NgsFormsFormArrayListComponent` inside `items` to render the rows,
730
+ * and `NgsFormsFormArrayAddItemComponent` / `NgsFormsFormArrayRemoveItemComponent` to let users change them.
731
+ */
305
732
  declare class NgsFormsFormArrayContainerComponent extends NgsFormsFormItemWithVisibleAndValidatorsBase<NgsFormItemArrayConfig> {
306
733
  private formArrayService;
307
734
  static key: string;
308
735
  constructor(formArrayService: NgsFormsFormArrayInternalService);
736
+ /** Creates a `form-array` item. */
309
737
  static create(config: NgsFormItemArrayConfig): NgsFormsFormItem<NgsFormItemArrayConfig>;
310
738
  static ɵfac: i0.ɵɵFactoryDeclaration<NgsFormsFormArrayContainerComponent, never>;
311
739
  static ɵcmp: i0.ɵɵComponentDeclaration<NgsFormsFormArrayContainerComponent, "ngs-forms-form-array", never, {}, {}, never, never, true, never>;
312
740
  }
313
741
 
742
+ /**
743
+ * Holds the `UntypedFormArray` of one `NgsFormsFormArrayContainerComponent` and is shared with its list and buttons.
744
+ *
745
+ * @remarks Inject it in a custom component placed inside a form array to add or remove rows programmatically.
746
+ */
314
747
  declare class NgsFormsFormArrayInternalService implements OnDestroy {
315
748
  config: NgsFormItemArrayConfig;
316
749
  readonly formArray: UntypedFormArray;
750
+ /** Emits after a row is added or removed. */
317
751
  readonly itemsChanged: Subject<void>;
318
752
  constructor();
319
753
  ngOnDestroy(): void;
754
+ /** Removes the row at `index`, unless that would go below `minItems`. */
320
755
  removeAt(index: number): void;
756
+ /** Appends an empty row, unless the array already has `maxItems` rows. */
321
757
  addItem(): void;
322
758
  static ɵfac: i0.ɵɵFactoryDeclaration<NgsFormsFormArrayInternalService, never>;
323
759
  static ɵprov: i0.ɵɵInjectableDeclaration<NgsFormsFormArrayInternalService>;
324
760
  }
325
761
 
762
+ /**
763
+ * A button that appends a row to the enclosing form array, up to `maxItems`.
764
+ *
765
+ * @remarks Registry key: `form-array-add-item`. Must be placed inside an `NgsFormsFormArrayContainerComponent`.
766
+ */
326
767
  declare class NgsFormsFormArrayAddItemComponent extends NgsFormsBaseClassFormComponent<NgsFormItemArrayAddItemConfig> {
327
768
  static key: string;
328
769
  internalArrayService: NgsFormsFormArrayInternalService;
770
+ /** Creates a `form-array-add-item` item. */
329
771
  static create(config: NgsFormItemArrayAddItemConfig): NgsFormsFormItem<NgsFormItemArrayAddItemConfig>;
330
772
  addItem(): void;
331
773
  static ɵfac: i0.ɵɵFactoryDeclaration<NgsFormsFormArrayAddItemComponent, never>;
332
774
  static ɵcmp: i0.ɵɵComponentDeclaration<NgsFormsFormArrayAddItemComponent, "ngs-forms-form-array-add-item", never, {}, {}, never, never, true, never>;
333
775
  }
334
776
 
777
+ /** Configuration for `NgsFormsFormArrayListComponent`. */
335
778
  interface NgsFormsFormArrayListConfig extends NgsFormsFormItemConfigBase {
779
+ /** The item rendered for each row, usually a row or column of inputs. */
336
780
  templateItem: NgsFormsFormItem<any>;
781
+ /** Class for the element that wraps each row. */
337
782
  containerClass?: string;
338
783
  }
339
784
 
785
+ /**
786
+ * Renders one copy of `templateItem` for every row of the enclosing form array. Each row gets its own form group,
787
+ * so the controls in the template become the properties of each array entry.
788
+ *
789
+ * @remarks Registry key: `form-array-list`. Must be placed inside an `NgsFormsFormArrayContainerComponent`.
790
+ */
340
791
  declare class NgsFormsFormArrayListComponent extends NgsFormsBaseClassFormComponent<NgsFormsFormArrayListConfig> implements OnInit {
341
792
  static key: string;
342
793
  internalArrayService: NgsFormsFormArrayInternalService;
343
794
  myFormArray: FormArray<any>;
344
795
  private changeDetectorRef;
345
796
  ngOnInit(): void;
797
+ /** Creates a `form-array-list` item. */
346
798
  static create(config: NgsFormsFormArrayListConfig): NgsFormsFormItem<NgsFormsFormArrayListConfig>;
347
799
  castToFormGroup(control: AbstractControl): UntypedFormGroup;
348
800
  static ɵfac: i0.ɵɵFactoryDeclaration<NgsFormsFormArrayListComponent, never>;
349
801
  static ɵcmp: i0.ɵɵComponentDeclaration<NgsFormsFormArrayListComponent, "ngs-forms-form-array-list", never, {}, {}, never, never, true, never>;
350
802
  }
351
803
 
804
+ /** Configuration for `NgsFormsFormArrayRemoveItemComponent`. */
352
805
  interface NgsFormItemArrayRemoveItemConfig extends NgsFormsFormItemConfigBase {
806
+ /**
807
+ * Button label.
808
+ * @defaultValue 'Remove'
809
+ */
353
810
  buttonText?: string;
811
+ /**
812
+ * Button class.
813
+ * @defaultValue 'btn btn-outline-danger btn-sm'
814
+ */
354
815
  buttonClass?: string;
816
+ /** Class of an `<i>` icon shown before the label, for example `bi bi-trash`. */
355
817
  buttonIcon?: string;
356
- onRemoveItem?: () => void;
357
818
  }
358
819
 
820
+ /**
821
+ * A button that removes its own row from the enclosing form array, down to `minItems`.
822
+ *
823
+ * @remarks Registry key: `form-array-remove-item`. Place it inside the `templateItem` of an
824
+ * `NgsFormsFormArrayListComponent` so each row gets one.
825
+ */
359
826
  declare class NgsFormsFormArrayRemoveItemComponent extends NgsFormsBaseClassFormComponent<NgsFormItemArrayRemoveItemConfig> {
360
827
  static key: string;
361
828
  internalArrayService: NgsFormsFormArrayInternalService;
362
829
  private elementRef;
363
830
  private indexFromDi;
831
+ /** Index of the row this button belongs to. */
364
832
  get myIndex(): number;
365
833
  constructor();
834
+ /** Creates a `form-array-remove-item` item. */
366
835
  static create(config: NgsFormItemArrayRemoveItemConfig): NgsFormsFormItem<NgsFormItemArrayRemoveItemConfig>;
367
836
  removeItem(): void;
368
837
  static ɵfac: i0.ɵɵFactoryDeclaration<NgsFormsFormArrayRemoveItemComponent, never>;
@@ -374,24 +843,43 @@ interface NgsFormsTextDivConfig extends NgsFormsFormItemConfigBase {
374
843
  classes?: string;
375
844
  }
376
845
 
846
+ /**
847
+ * Renders a line of static text, such as a heading or a hint, inside the form.
848
+ *
849
+ * @remarks Registry key: `text-div`. Config: `text` and optional `classes`.
850
+ */
377
851
  declare class NgsFormsTextDivComponent extends NgsFormsBaseClassFormComponent<NgsFormsTextDivConfig> {
378
852
  static key: string;
853
+ /** Creates a `text-div` item. */
379
854
  static create(config: NgsFormsTextDivConfig): NgsFormsFormItem<NgsFormsTextDivConfig>;
855
+ /**
856
+ * Shortcut for a heading: creates a `text-div` with `text` and the given class (default `h2`).
857
+ */
380
858
  static title(title: string, divClass?: string): NgsFormsFormItem<NgsFormsTextDivConfig>;
381
859
  static ɵfac: i0.ɵɵFactoryDeclaration<NgsFormsTextDivComponent, never>;
382
860
  static ɵcmp: i0.ɵɵComponentDeclaration<NgsFormsTextDivComponent, "ngs-form-component-text-div", never, {}, {}, never, never, true, never>;
383
861
  }
384
862
 
863
+ /** Configuration for `NgsFormsHtmlContentComponent`. */
385
864
  interface NgsFormItemHtmlContentConfig extends NgsFormsFormItemConfigBase {
865
+ /** The HTML to render. */
386
866
  html: string;
867
+ /** Reserved. The HTML is always sanitized. */
387
868
  sanitize: boolean;
388
869
  }
389
870
 
871
+ /**
872
+ * Renders an HTML string inside the form. The HTML is passed through Angular's sanitizer.
873
+ *
874
+ * @remarks Registry key: `content-html`. Registered by `registerCoreNgsFormComponents()`, which the theme packages'
875
+ * `registerAll…` helpers call for you.
876
+ */
390
877
  declare class NgsFormsHtmlContentComponent extends NgsFormsBaseClassFormComponent<NgsFormItemHtmlContentConfig> {
391
878
  static key: string;
392
879
  contentConfig: NgsFormItemHtmlContentConfig;
393
880
  html: string;
394
881
  constructor();
882
+ /** Creates a `content-html` item. */
395
883
  static create(config: NgsFormItemHtmlContentConfig): NgsFormsFormItem<NgsFormItemHtmlContentConfig>;
396
884
  static ɵfac: i0.ɵɵFactoryDeclaration<NgsFormsHtmlContentComponent, never>;
397
885
  static ɵcmp: i0.ɵɵComponentDeclaration<NgsFormsHtmlContentComponent, "ngs-form-component-html-content", never, {}, {}, never, never, true, never>;
@@ -404,18 +892,33 @@ interface NgsFormsFormSectionConfig extends NgsFormsFormItemContainerConfigBase
404
892
  subtitleClass?: string;
405
893
  }
406
894
 
895
+ /**
896
+ * Groups items under a title and optional subtitle. Does not create a form control, so child values stay in the
897
+ * parent group.
898
+ *
899
+ * @remarks Registry key: `section`. Config: `title`, `subtitle`, `titleClass` (default `h3`),
900
+ * `subtitleClass` (default `lead`) and `items`.
901
+ */
407
902
  declare class NgsFormsFormSectionComponent extends NgsFormsBaseClassItemsContainerBase<NgsFormsFormSectionConfig> implements OnInit {
408
903
  static key: string;
904
+ /** Creates a `section` item. */
409
905
  static create(config: NgsFormsFormSectionConfig): NgsFormsFormItem<NgsFormsFormSectionConfig>;
410
906
  ngOnInit(): void;
411
907
  static ɵfac: i0.ɵɵFactoryDeclaration<NgsFormsFormSectionComponent, never>;
412
908
  static ɵcmp: i0.ɵɵComponentDeclaration<NgsFormsFormSectionComponent, "ngs-forms-form-section", never, {}, {}, never, never, true, never>;
413
909
  }
414
910
 
911
+ /** Registration helpers for the structural components in `@ng-simplicity/forms-core`. */
415
912
  declare class NgsFormsCoreModule {
913
+ /**
914
+ * Registers the structural components: `form-group`, `form-row`, `column`, `form-array`, `form-array-list`,
915
+ * `form-array-add-item`, `form-array-remove-item`, `text-div`, `content-html` and `section`.
916
+ *
917
+ * @remarks The theme packages call this for you from their own `registerAll…` helpers.
918
+ */
416
919
  static registerCoreNgsFormComponents(registryService: NgsFormsComponentRegistryService): void;
417
920
  static ɵfac: i0.ɵɵFactoryDeclaration<NgsFormsCoreModule, never>;
418
- static ɵmod: i0.ɵɵNgModuleDeclaration<NgsFormsCoreModule, never, [typeof i1.CommonModule, typeof i2.FormsModule, typeof i2.ReactiveFormsModule], never>;
921
+ static ɵmod: i0.ɵɵNgModuleDeclaration<NgsFormsCoreModule, never, [typeof i1.CommonModule, typeof _angular_forms.FormsModule, typeof _angular_forms.ReactiveFormsModule], never>;
419
922
  static ɵinj: i0.ɵɵInjectorDeclaration<NgsFormsCoreModule>;
420
923
  }
421
924