@3kles/kles-material-dynamicforms 19.4.2 → 19.4.4

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
 
@@ -507,12 +517,19 @@ class GroupUiState extends AbstractUiState {
507
517
  constructor(states) {
508
518
  super();
509
519
  this.states = {};
510
- this.states = states;
520
+ this._computedValue = computed(() => {
521
+ return this._snapshot();
522
+ });
523
+ this.states = (states ?? {});
524
+ this._value.set(this._snapshot());
511
525
  }
512
526
  setValue(value) {
527
+ if (value == null)
528
+ return;
513
529
  Object.keys(value).forEach((name) => {
514
530
  this.states[name]?.setValue(value[name]);
515
531
  });
532
+ this._value.set(value);
516
533
  }
517
534
  patchValue(value) {
518
535
  if (value == null)
@@ -523,12 +540,28 @@ class GroupUiState extends AbstractUiState {
523
540
  state.patchValue(value[name]);
524
541
  }
525
542
  });
543
+ const curr = this._value() ?? {};
544
+ this._value.set({ ...curr, ...value });
526
545
  }
527
546
  _find(name) {
528
- 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;
529
550
  }
530
551
  addUiState(name, uiState) {
531
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;
532
565
  }
533
566
  }
534
567
 
@@ -1981,7 +2014,6 @@ let KlesFormCheckboxComponent = class KlesFormCheckboxComponent extends KlesFiel
1981
2014
  }
1982
2015
  static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.2.18", ngImport: i0, type: KlesFormCheckboxComponent, deps: null, target: i0.ɵɵFactoryTarget.Component }); }
1983
2016
  static { this.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "19.2.18", type: KlesFormCheckboxComponent, isStandalone: true, selector: "kles-form-checkbox", usesInheritance: true, ngImport: i0, template: `
1984
- {{ indeterminate() }}
1985
2017
  <div [formGroup]="group">
1986
2018
  <mat-checkbox matTooltip="{{ field.tooltip }}" [attr.id]="field.id" [ngClass]="ngClass()" [indeterminate]="indeterminate()" (change)="onChange($event)" [color]="color()" [formControlName]="field.name">{{ field.label }}</mat-checkbox>
1987
2019
  </div>
@@ -1993,7 +2025,6 @@ KlesFormCheckboxComponent = __decorate([
1993
2025
  i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.18", ngImport: i0, type: KlesFormCheckboxComponent, decorators: [{
1994
2026
  type: Component,
1995
2027
  args: [{ selector: 'kles-form-checkbox', template: `
1996
- {{ indeterminate() }}
1997
2028
  <div [formGroup]="group">
1998
2029
  <mat-checkbox matTooltip="{{ field.tooltip }}" [attr.id]="field.id" [ngClass]="ngClass()" [indeterminate]="indeterminate()" (change)="onChange($event)" [color]="color()" [formControlName]="field.name">{{ field.label }}</mat-checkbox>
1999
2030
  </div>
@@ -4280,27 +4311,45 @@ class ArrayUiState extends AbstractUiState {
4280
4311
  constructor(states) {
4281
4312
  super();
4282
4313
  this.states = [];
4283
- this.states = states;
4314
+ this._computedValue = computed(() => {
4315
+ return this.states.map((s) => s.value());
4316
+ });
4317
+ this.states = states ?? [];
4318
+ this._value.set(this.states.map((s) => s.value()));
4319
+ }
4320
+ get value() {
4321
+ return this._computedValue;
4284
4322
  }
4285
4323
  setValue(value) {
4324
+ if (!Array.isArray(value)) {
4325
+ return;
4326
+ }
4286
4327
  value.forEach((newValue, index) => {
4287
- this.at(index).setValue(newValue);
4328
+ this.at(index)?.setValue(newValue);
4288
4329
  });
4330
+ this._value.set(value);
4289
4331
  }
4290
4332
  patchValue(value) {
4291
- if (value == null)
4333
+ if (value == null) {
4292
4334
  return;
4335
+ }
4293
4336
  value.forEach((newValue, index) => {
4294
- if (this.at(index)) {
4295
- this.at(index).patchValue(newValue);
4337
+ const st = this.at(index);
4338
+ if (st) {
4339
+ st.patchValue(newValue);
4296
4340
  }
4297
4341
  });
4342
+ const curr = this._value() ?? [];
4343
+ const next = [...curr];
4344
+ value.forEach((v, i) => (next[i] = v));
4345
+ this._value.set(next);
4298
4346
  }
4299
4347
  at(index) {
4300
- return this.states?.[index];
4348
+ return this.states?.[index] ?? null;
4301
4349
  }
4302
4350
  _find(name) {
4303
- return this.at(name) ?? null;
4351
+ const idx = typeof name === 'number' ? name : Number(name);
4352
+ return Number.isFinite(idx) ? this.at(idx) : null;
4304
4353
  }
4305
4354
  push(control) {
4306
4355
  if (Array.isArray(control)) {
@@ -4311,6 +4360,7 @@ class ArrayUiState extends AbstractUiState {
4311
4360
  else {
4312
4361
  this.states.push(control);
4313
4362
  }
4363
+ this._value.set(this.states.map((s) => s.value()));
4314
4364
  }
4315
4365
  }
4316
4366