@rxdi/forms 0.7.216 → 0.7.217

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.
@@ -11,6 +11,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
12
  exports.FormGroup = void 0;
13
13
  const rxjs_1 = require("rxjs");
14
+ const operators_1 = require("rxjs/operators");
14
15
  const form_tokens_1 = require("./form.tokens");
15
16
  class FormGroup {
16
17
  constructor(value, errors) {
@@ -44,6 +45,7 @@ class FormGroup {
44
45
  }
45
46
  });
46
47
  }
48
+ this.prepareValues();
47
49
  }
48
50
  init() {
49
51
  if (!this.parentElement) {
@@ -343,7 +345,33 @@ class FormGroup {
343
345
  return control.get(names.join('.'));
344
346
  }
345
347
  }
346
- return this.inputs.get(name);
348
+ const input = this.inputs.get(name);
349
+ if (input) {
350
+ return input;
351
+ }
352
+ /*
353
+ If a user tries to subscribe on a constructor level or before the inputs are inside the DOM
354
+ We create a fake Virtual Input so later on when elements present on stage to get the same subscription
355
+ */
356
+ const key = name;
357
+ // Check if key exists in the model value even if not in inputs map
358
+ if (this._valueChanges.getValue() && key in this._valueChanges.getValue()) {
359
+ // Create a "Virtual" AbstractInput to prevent crashes and allow subscription even if no DOM element present
360
+ return {
361
+ valueChanges: this._valueChanges.pipe((0, operators_1.map)((value) => value === null || value === void 0 ? void 0 : value[key]), (0, operators_1.distinctUntilChanged)()),
362
+ value: this.getValue(key),
363
+ name: String(key),
364
+ valid: true,
365
+ invalid: false,
366
+ dirty: false,
367
+ touched: false,
368
+ // Mock HTMLInputElement properties to satisfy interface if needed
369
+ type: 'text',
370
+ checked: false,
371
+ disabled: false,
372
+ };
373
+ }
374
+ return undefined;
347
375
  }
348
376
  getError(inputName, errorKey) {
349
377
  return this.errors[inputName][errorKey];
@@ -431,6 +459,7 @@ class FormGroup {
431
459
  this.inputs = new Map(inputs.map((e) => {
432
460
  const key = this.getModelKeyName(e.name);
433
461
  e.value = this.getValue(key);
462
+ e.valueChanges = this._valueChanges.pipe((0, operators_1.map)((value) => value === null || value === void 0 ? void 0 : value[key]), (0, operators_1.distinctUntilChanged)());
434
463
  return [key, e];
435
464
  }));
436
465
  }
@@ -6,10 +6,10 @@ export type UnwrapValue<T> = T extends AbstractControl<infer U> ? U : T extends
6
6
  [K in keyof T]: UnwrapValue<T[K]>;
7
7
  } : T;
8
8
  type Prev = [never, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, ...0[]];
9
- export type NestedKeyOf<T, D extends number = 3> = [D] extends [0] ? never : T extends object ? {
9
+ export type NestedKeyOf<T, D extends number = 3> = [D] extends [0] ? never : T extends Array<any> ? never : T extends object ? {
10
10
  [K in keyof T & (string | number)]: T[K] extends AbstractControl<infer U> ? U extends object ? `${K}` | `${K}.${NestedKeyOf<U, Prev[D]>}` : `${K}` : T[K] extends object ? `${K}` | `${K}.${NestedKeyOf<T[K], Prev[D]>}` : `${K}`;
11
11
  }[keyof T & (string | number)] : never;
12
- export type DeepPropType<T, P extends string> = P extends keyof T ? T[P] : P extends `${infer K}.${infer R}` ? K extends keyof T ? DeepPropType<T[K], R> : any : any;
12
+ export type DeepPropType<T, P extends string> = P extends keyof T ? T[P] extends [infer V, ValidatorFn[]] ? AbstractInput<V> : T[P] extends (infer U)[] ? AbstractInput<U> : T[P] extends string | number | boolean ? AbstractInput<T[P]> : T[P] : P extends `${infer K}.${infer R}` ? K extends keyof T ? DeepPropType<T[K], R> : any : any;
13
13
  export type FormStrategies = keyof WindowEventMap;
14
14
  export interface FormOptions {
15
15
  /** Name of the form element */
@@ -19,7 +19,7 @@ export interface FormOptions {
19
19
  /** Multiple input elements like checkboxes with the same name will be binded together */
20
20
  multi?: boolean;
21
21
  /** When set to true `.valueChanges` will emit values only
22
- * if current input validation passes, default behavior is to emit every change fro */
22
+ * if current input validation passes, default behavior is to emit every change on the form */
23
23
  strict?: boolean;
24
24
  /**
25
25
  * When set form will expand capabilities by selecting another custom element made as a form element
@@ -63,11 +63,12 @@ export interface ErrorObject {
63
63
  element: HTMLInputElement;
64
64
  errors: InputErrorMessage[];
65
65
  }
66
- export interface AbstractInput extends HTMLInputElement {
66
+ export interface AbstractInput<T = any> extends HTMLInputElement {
67
67
  valid?: boolean;
68
68
  invalid?: boolean;
69
69
  dirty?: boolean;
70
70
  touched?: boolean;
71
+ valueChanges?: Observable<any>;
71
72
  }
72
73
  export declare const InputValidityState: {
73
74
  badInput: "badInput";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rxdi/forms",
3
- "version": "0.7.216",
3
+ "version": "0.7.217",
4
4
  "main": "./dist/index.js",
5
5
  "author": "Kristiyan Tachev",
6
6
  "license": "MIT",
@@ -12,7 +12,7 @@
12
12
  "build": "tsc"
13
13
  },
14
14
  "devDependencies": {
15
- "@rxdi/lit-html": "^0.7.215",
15
+ "@rxdi/lit-html": "^0.7.216",
16
16
  "@types/node": "^25.0.3",
17
17
  "rxjs": "^7.8.2",
18
18
  "typescript": "^5.9.3"