@3kles/kles-material-dynamicforms 19.4.1 → 19.4.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.
@@ -1,5 +1,5 @@
1
1
  import * as i0 from '@angular/core';
2
- import { signal, InjectionToken, inject, Component, Injector, Input, Directive, Injectable, EventEmitter, Output, NgModule, computed, ViewContainerRef, HostBinding, Pipe, ChangeDetectorRef, ViewChildren, ViewChild, forwardRef, CUSTOM_ELEMENTS_SCHEMA, NO_ERRORS_SCHEMA } from '@angular/core';
2
+ import { signal, InjectionToken, inject, Component, Injector, Input, Directive, Injectable, computed, EventEmitter, Output, NgModule, ViewContainerRef, HostBinding, Pipe, ChangeDetectorRef, ViewChildren, ViewChild, forwardRef, CUSTOM_ELEMENTS_SCHEMA, NO_ERRORS_SCHEMA } from '@angular/core';
3
3
  import * as i1 from '@angular/common';
4
4
  import { CommonModule } from '@angular/common';
5
5
  import * as i2 from '@angular/forms';
@@ -136,7 +136,7 @@ class AbstractUiState {
136
136
  if (currPath == null)
137
137
  return null;
138
138
  if (!Array.isArray(currPath))
139
- currPath = currPath.split('.');
139
+ currPath = currPath.split('.').filter(Boolean);
140
140
  if (currPath.length === 0)
141
141
  return null;
142
142
  return currPath.reduce((uiState, name) => uiState && uiState._find(name), this);
@@ -152,13 +152,23 @@ class AbstractUiState {
152
152
  class ControlUiState extends AbstractUiState {
153
153
  constructor(value) {
154
154
  super();
155
- this._value.set(value);
155
+ if (value !== undefined) {
156
+ this._value.set(value);
157
+ }
156
158
  }
157
159
  setValue(value) {
158
160
  this._value.set(value);
159
161
  }
160
162
  patchValue(value) {
161
- this.setValue(value);
163
+ if (value == null) {
164
+ return;
165
+ }
166
+ const curr = this._value();
167
+ if (curr == null) {
168
+ this._value.set(value);
169
+ return;
170
+ }
171
+ this._value.set({ ...curr, ...value });
162
172
  }
163
173
  }
164
174
 
@@ -504,14 +514,22 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.18", ngImpo
504
514
  }], ctorParameters: () => [] });
505
515
 
506
516
  class GroupUiState extends AbstractUiState {
507
- constructor() {
508
- super(...arguments);
517
+ constructor(states) {
518
+ super();
509
519
  this.states = {};
520
+ this._computedValue = computed(() => {
521
+ return this._snapshot();
522
+ });
523
+ this.states = (states ?? {});
524
+ this._value.set(this._snapshot());
510
525
  }
511
526
  setValue(value) {
527
+ if (value == null)
528
+ return;
512
529
  Object.keys(value).forEach((name) => {
513
530
  this.states[name]?.setValue(value[name]);
514
531
  });
532
+ this._value.set(value);
515
533
  }
516
534
  patchValue(value) {
517
535
  if (value == null)
@@ -522,12 +540,28 @@ class GroupUiState extends AbstractUiState {
522
540
  state.patchValue(value[name]);
523
541
  }
524
542
  });
543
+ const curr = this._value() ?? {};
544
+ this._value.set({ ...curr, ...value });
525
545
  }
526
546
  _find(name) {
527
- return this.states.hasOwnProperty(name) ? this.states[name] : null;
547
+ const key = String(name);
548
+ const has = Object.prototype.hasOwnProperty.call(this.states, key);
549
+ return has ? this.states[key] : null;
528
550
  }
529
551
  addUiState(name, uiState) {
530
552
  this.states[name] = uiState;
553
+ const curr = this._value() ?? {};
554
+ this._value.set({ ...curr, [name]: uiState.value() });
555
+ }
556
+ get value() {
557
+ return this._computedValue;
558
+ }
559
+ _snapshot() {
560
+ const out = {};
561
+ for (const key of Object.keys(this.states)) {
562
+ out[key] = this.states[key]?.value();
563
+ }
564
+ return out;
531
565
  }
532
566
  }
533
567
 
@@ -4276,29 +4310,48 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.18", ngImpo
4276
4310
  }] });
4277
4311
 
4278
4312
  class ArrayUiState extends AbstractUiState {
4279
- constructor() {
4280
- super(...arguments);
4313
+ constructor(states) {
4314
+ super();
4281
4315
  this.states = [];
4316
+ this._computedValue = computed(() => {
4317
+ return this.states.map((s) => s.value());
4318
+ });
4319
+ this.states = states ?? [];
4320
+ this._value.set(this.states.map((s) => s.value()));
4321
+ }
4322
+ get value() {
4323
+ return this._computedValue;
4282
4324
  }
4283
4325
  setValue(value) {
4326
+ if (!Array.isArray(value)) {
4327
+ return;
4328
+ }
4284
4329
  value.forEach((newValue, index) => {
4285
- this.at(index).setValue(newValue);
4330
+ this.at(index)?.setValue(newValue);
4286
4331
  });
4332
+ this._value.set(value);
4287
4333
  }
4288
4334
  patchValue(value) {
4289
- if (value == null)
4335
+ if (value == null) {
4290
4336
  return;
4337
+ }
4291
4338
  value.forEach((newValue, index) => {
4292
- if (this.at(index)) {
4293
- this.at(index).patchValue(newValue);
4339
+ const st = this.at(index);
4340
+ if (st) {
4341
+ st.patchValue(newValue);
4294
4342
  }
4295
4343
  });
4344
+ const curr = this._value() ?? [];
4345
+ const next = [...curr];
4346
+ value.forEach((v, i) => (next[i] = v));
4347
+ this._value.set(next);
4296
4348
  }
4297
4349
  at(index) {
4298
- return this.states?.[index];
4350
+ return this.states?.[index] ?? null;
4299
4351
  }
4300
4352
  _find(name) {
4301
- return this.at(name) ?? null;
4353
+ const idx = typeof name === 'number' ? name : Number(name);
4354
+ return Number.isFinite(idx) ? this.at(idx) : null;
4302
4355
  }
4303
4356
  push(control) {
4304
4357
  if (Array.isArray(control)) {
@@ -4309,6 +4362,7 @@ class ArrayUiState extends AbstractUiState {
4309
4362
  else {
4310
4363
  this.states.push(control);
4311
4364
  }
4365
+ this._value.set(this.states.map((s) => s.value()));
4312
4366
  }
4313
4367
  }
4314
4368